Java Servlets: performance

I am working on a Java web application that receives data from servlets through AJAX calls.

This application contains several page elements that receive quick requests for new data from the server.

With a large number of users, the demand on the server can become quite high, so I wonder:

Which approach provides the best performance:

Many servlets (one for each type of data request)?

Or:

one servlet that can handle all requests?

+4
source share
6 answers

There is no reason to create more than one servlet. A web application processes only one instance of a servlet class, regardless of the number of requests. Requests are not serialized, they are processed simultaneously, therefore, the need to ensure the security of your servlet.

+11
source

framework struts uses one servlet for everything in your application. Your stuff connects to one servlet. If this works for them, it will probably work for you.

+2
source

One of the possible reasons for using several services is that if you need to switch to several servers to handle the load in the future, it is easier to move a separate service to your own server than to do it "behind the scenes" if everything comes from one service.

There is additional overhead if you have several servlets, so this is a matter of balancing future flexibility with less maintainability.

+1
source

In this case, there are no performance improvements if you use multiple servlets, since for each request the servlet is processed in a separate thread, provided that it is not single.

But while maintaining modularity and code separation, you can have multiple servlets.

+1
source

As Tony said, there really is no reason to use more than one servlet unless you need to break up the complex Java Servlet class or perhaps implement an interception filter.

0
source

I am sure that you know that you can have several instances of the same servlet if you register different nodes in the web.xml file for your application, i.e. provided that you want to do this.

In addition, from what I understand, you can use the architecture of the comet - http://en.wikipedia.org/wiki/Comet_(programming) .
There are already some comet implementations on some servlet containers - here is one look at how to use Ajax and Comet - http://www.ibm.com/developerworks/java/library/j-jettydwr/ . You must learn before deciding on your architecture.

BR,
~ A

0
source

Source: https://habr.com/ru/post/1277756/


All Articles