How to configure Spring boot 2.4 server threads in undertow? - spring

How to configure spring boot server threads (for both IO and Worker) for undertow embedded server?
Thanks in advance.

As per the documentation:
server.undertow.threads.io //Number of I/O threads to create for the worker. The default is derived from the number of available processors.
server.undertow.threads.worker //Number of worker threads. The default is 8 times the number of I/O threads.

Related

Spring Kafka Consumer Threadpool

I am using Spring Kafka Consumer. I have set the concurrency to 10 and have 5 consumers created (for 5 topics). So there are 50 Spring Kafka Consumer threads.
What is the maximum number of threads I can have for Kafka Consumers? How can I increase the size of this thread pool? I have gone over the spring documentation but didn't find anything relavent.
There is no limit; by default, each container uses a SimpleAsyncTaskExecutor for the threads; there is no pool involved.

Spring Boot Embedded Tomcat Internal Working

I recently read an article regarding Tomcat architecture and a high level overview of its working and monitoring.
Key metrics for monitoring Tomcat - DataDog
In this article, it mentions Tomcat having a pool of worker threads per connector that can be configured.
It also mentions about Executors and how it is mainly a thread pool that is shared with multiple connectors.
I have some doubts regarding Spring Boot and its Embedded Tomcat Server
How many Connectors are configured by default for this embedded Tomcat Server?
Does the embedded Tomcat have an Executor configured? Or is it just the basic pool of worker threads.
I can see that we can configure the accept count using application.properties by using the following property
server.tomcat.accept-count
I believe acceptCount sets the max number of connections that can be queued up in the OS level queue when no worker thread is available. ( As per the mentioned article )
Does this mean that there is no Executor configured for the default Connector? If there is, how do we configure the queue size of that executor?
I would be grateful if someone could shed some light on the above.
In short, I just wanted to know if the server configuration via application.propeties is for an Executor or for the Connector specific pool of worker threads.

Monitoring tomcat threads and threadpool executors using Spring Boot Actuator

We are doing some performance testing of our application which uses SpringBoot 2.2.2 with Spring Actuator.
We want to monitor:
How many tomcat threads are being used
How many tomcat requests are being queued
How many ThreadPoolTaskExecutor threads are being used (we are using #Async with a threadpool for some of the tasks)
Is this information available in the actuator? I couldn't see which metrics I needed to use.
By enabling Tomcats MBean Registry you will get more metrics collected, including thread pool metrics:
server.tomcat.mbeanregistry.enabled=true

Reduce # of threads created when a Spring Boot-based service is listening on many ports?

This is probably a rather peculiar question. I am using Spring Boot 2.0.2 with the default Tomcat container. In order to set up a test in our QA environment that simulates many servers, I would like to set up a Spring Boot-based REST service that listens on a very large number of ports simultaneously. I'm able to do this using the technique previously described in in another SO post (Configure Spring Boot with two ports) which basically adds connectors using TomcatServletWebServerFactory.addAdditionalTomcatConnectors().
The difficulty is that a large number of threads seem to be created for each additional port activated; some empirical measurements show the total to be 17 + (15 * number of ports). This means listening on 250 ports result in 3767 threads created and 500 ports result in 7517 threads created and I would like to go somewhat beyond that number. The test program used to take the above measurements is the bare minimum to bring up a Spring service and there is no code that creates threads explicitly so insofar, as I know, all of those threads were created by Spring/Tomcat.
Is there a way to accomplish this using Spring that doesn't use so many threads per active port? Would an alternate container like Jetty be more efficient?
You can configure the embedded tomcat container properties in spring boot configuration file and set the appropriate numbers for these properties to limit the threads created by Tomcat container -
server.tomcat.max-threads=200 # Maximum amount of worker threads.
server.tomcat.min-spare-threads=10 # Minimum amount of worker threads.

Spring WebFlux create pool of no-blocking threads

I decided to rewrite my web app on Java(previously it was on Python).
In my app I used no-blocking I/O, I had worker pool(Celery + Eventlet threads) where I pass tasks which consists of hundreds of API calls.
Now I'm using Spring WebFlux but I can't understand how I can create a workers pool to pass my tasks to that pool, and after get results and do some calculations.
(I know about possibility to create ThreadPoolTaskExecutor, but the threads are blocking threads)
If you're using non-blocking APIs, you don't need to schedule tasks on specific threads - Reactor is doing that for you. With Spring WebFlux, the threads used for processing work are managed by Reactor or it is reusing the Netty threads.
Check out the Schedulers and threading parts of the reactor reference documentation.

Resources