Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to optimize Tomcat for Feed pull

Tags:

java

tomcat

akka

We have a mobile app which presents feed to users. The feed REST API is implemented on tomcat, which parallel makes calls to different data sources such as Couchbase, MYSQL to present the content. The simple code is given below:

Future<List<CardDTO>> pnrFuture = null;
Future<List<CardDTO>> newsFuture = null;

ExecutionContext ec = ExecutionContexts.fromExecutorService(executor);

final List<CardDTO> combinedDTOs = new ArrayList<CardDTO>();

// Array list of futures 
List<Future<List<CardDTO>>> futures = new ArrayList<Future<List<CardDTO>>>();

futures.add(future(new PNRFuture(pnrService, userId), ec)); 
futures.add(future(new NewsFuture(newsService, userId), ec)); 
futures.add(future(new SettingsFuture(userPreferenceManager, userId), ec)); 

Future<Iterable<List<CardDTO>>> futuresSequence = sequence(futures, ec); 

// combine the cards 
Future<List<CardDTO>> futureSum =  futuresSequence.map( 
        new Mapper<Iterable<List<CardDTO>>, List<CardDTO>>() {
            @Override 
            public List<CardDTO> apply(Iterable<List<CardDTO>> allDTOs) { 
                for (List<CardDTO> cardDTOs : allDTOs) {
                    if (cardDTOs != null) {
                        combinedDTOs.addAll(cardDTOs);
                    } 
                } 

                Collections.sort(combinedDTOs);
                return combinedDTOs;
            } 
        } 
); 

Await.result(futureSum, Duration.Inf());  
return combinedDTOs; 

Right now we have around 4-5 parallel tasks per request. But it is expected to grow to almost 20-25 parallel tasks as we introduce new kinds of items in feed.

My question is, how can I improve this design? What kind of tuning is required in Tomcat to make sure such 20-25 parallel calls can be served optimally under heavy load.

I understand this is a broad topic, but any suggestions would be very helpful.

like image 444
Madhur Ahuja Avatar asked Jan 28 '16 17:01

Madhur Ahuja


People also ask

Which method is used for improving performance of Tomcat with a database?

To maximize the effectiveness of this technique, use the -Xms switch to ensure that the JVM's initial heap memory size is equal to the maximum allocated memory. This will keep the Tomcat JVM from having to reallocate and resize its heap memory, which will free up additional CPU cycles for Tomcat to serve requests.

Why is Tomcat slow?

For Tomcat itself to run slow would mean that the VM it's running in was severely starved for resources. So, for example, if Tomcat is running slow, you should check to make sure that the machine that Tomcat is running on has enough physical RAM that it isn't thrashing virtual memory.

How do I monitor Tomcat?

The default port for Tomcat is 8080. To check if Tomcat is running, open any browser and enter the address http://localhost:8080. If Tomcat is running, you will see the Tomcat homepage in your browser. You might have set up Tomcat to run on some other port.


1 Answers

Tomcat just manages the incoming HTTP connections and pushes the bytes back and forth. There is no Tomcat optimization that can be done to make your application run any better.

If you need 25 parallel processes to run for each incoming HTTP request, and you think that's crazy, then you need to re-think how your application works.

No tomcat configuration will help with what you've presented in your question.

like image 133
Christopher Schultz Avatar answered Oct 28 '22 06:10

Christopher Schultz