• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

memory per servlet connection in tomcat

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I looked around a bit, and really could not get a solid answer on this (and perhaps there is no solid answer without profiling). I am just wondering, in general, how much an extra concurrent servlet connection will take in memory. I know there are likely many factors that will affect this (I am using tomcat 7, BIO, on Ubuntu 32 bit, sun JVM). But ignoring code that I might add, around much memory does each thread take?

I do not want to make this into a flame war, but the reason I ask this is I am starting a new project and was considering using PHP. However, I was noticing that each php process was taking about 8-10 MB (which kind of makes sense considering how php does some things). This seemed a bit high for our server and the number of users we will want. So, I am just wondering if anyone has a good guestimate with this within tomcat.

Thanks,

-Adam
 
Sheriff
Posts: 67266
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlets do not need to spawn a new process for each connection so the overhead will be far far less than solutions that do.
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tomcat also has connection pools, and the memory used for each connection stays in memory and is reused between connections. Also, there are limits on the connection pools, and if too many connections come in, it will give the client a "server busy" error message. If you really need to measure, you need to take inot account Tomcat's pooling behavior and behavior of GC.

All in all, IME, the memory used by tomcat is insignificant compared to the memory used by the servlet itself.

IMO, the question that you need to ask is
a) how many connections are you expecting?
b) how much hardware can you afford?
c) What's the technology that will meet your demand while giving you the fastest turnaround time?
d) Will the technology allow you to scale up easily when your demand increases

If that technology happens to be PHP, then pfft. so be it. An overhead of 10MB is not significant. That translates to 200 concurrent reqeusts on a 2GB machine. Are you expecting more than 200 connections. Will you be able to implement your application faster in PHP than in Java? What's the cost of implementing a solution in PHP vs Java?
 
Bartender
Posts: 20836
125
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And finally, and most importantly, HTTP (Tomcat) is not a continuous-conversation protocol.

Unlike time-sharing client/server systems, web users do not establish a connection and hold it until they log out. HTTP is a one-off protocol where the cycle consists of:

1) Connect client to server
2) Client sends request to server
3) Server processes request
4) Server sends response back to client
5) Connection between client and server is closed

Although modern webservers generally boost performance using a "keep-alive" mechanism, the core HTTP protocol determines the number of connections by the number of active requests being processed and not by the number of users logged in.
 
adam spline
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all your and your suggestions.

To answer some of your questions,

Will you be able to implement your application faster in PHP than in Java? What's the cost of implementing a solution in PHP vs Java?



While Java is my primary language, I was dabbling in PHP for this project, because some of web services I was using seemed to have PHP clients that were easier to integrate. So, I started taking a shot at a php solution. I was able to start the development really fast because the PHP client functions were so easy to drop into the code. But, I noticed my memory usage was high per connection with PHP (as I indicated in my original post). So, I took a little time to re-look at it, and was able to get everything working fine in Java with a bit more effort. Thrashing it with Jmeter, the Java solution is faster, and I can handle a larger number of connections on smaller server (using tomcat standalone). Once I get through a bit of the hurdles of setting up things up, I think the cost development cost with Java will not be too much higher than the PHP. So, I am going forward with the Java solution. (I do not want to make this a flame war on languages, I am just sharing my experience and how I decided to deal with it).

Although modern webservers generally boost performance using a "keep-alive" mechanism, the core HTTP protocol determines the number of connections by the number of active requests being processed and not by the number of users logged in.



I was using the term "users" rather loosely . Yes, http is a request/response protocol. However, I do not think it is terribly incorrect to think of webserver load in terms of "users", depending on how we define the term. For example, we can think of users as those who are actively clicking around, (as opposed to those who are logged in). With Keep alives on (within say apache), an entire process is held up until the keep alive is done. And often those processes are heavy with mod_php, so each keep alive process will be consuming quite a bit of memory. So, with apache keep alives and 100 maxclients... if a system has 100 users clicking around every 15 seconds, the system is pretty much maxed out, regardless of how fast an individual request/response time is. Of course we can make the keep alives shorter to make the situation better (which I think is a pretty good idea), but the defaults for apache and tomcat are 15 and 20 seconds... This is more along the lines of what I was thinking about when I spoke of "users."


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!