V
V
vepr852019-03-04 12:30:51
Java
vepr85, 2019-03-04 12:30:51

What are the best practices to choose for a multi-threaded java service architecture?

I am making a small application on SpringBoot - a metrics aggregator. One of the tasks is to get certain metrics from another service (metrics service) for the time limit specified in the aggregator settings. That is, the user makes a request to the aggregator, which, in turn, must, for example, make as many requests to the metrics service as possible in 500 ms, discard all that he did not manage to receive in the specified time and perform certain processing on the result and give it to the user. Initially, I planned to use executorService and Future objects to check if there is a result from the request through the get () method and then aggregate all this according to certain logic. It is not clear how many threads to generate in the executor when the application starts, is it possible to somehow calculate this? The question is what are the problems in such an architecture, how to do it better?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vooft, 2019-05-13
@vooft

If the requests are fast, then you should start with the number of threads equal to the number of cores. Encoding/decoding requests will still be limited per core.
If the duration of requests can be different, then you should look at NIO - you can achieve much greater parallelism there, but still limit the processing to the number of cores.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question