简体   繁体   中英

How to scale a java based web application as the number of parallel sessions increase?

I have a java based(spring/hibernate) web application in which user can perform 6 different tasks. Each task creates a thread pool of 30 threads. Threading is used to increase the throughput/performance of the application.

Multiple users can login into the application at the same time and perform any of these 6 tasks.

Ex: 
User 1 logins - performs task 1 - 30 threads get created
User 2 logins - performs task 3 - 30 threads are created.
As user1 and user2 login at the same time, there are 60 active threads. 

As more users login, more and more live threads get created. Concern here is that the application will end up in an OOM with enormous amount of threads being active.

Is there a different structure or mechanism that can be used to solve this issue?

Can the number of parallel sessions be scaled without significantly impacting the performance of the application?

Once you start increasing the number of users you will eventually run out of the resources that your machine or your JVM can provide. In your case it seems to be threads which translates to memory and CPU.

You will need to use more machines and JVM instances. You may need stateless architecture to do so.

User Browsers --> Load Balancer --> Farm of stateless WebApp servers --> Database

The thing that you need to take care of, in this architecture, is that you should not store/cache any shared data or session data in your WebApp. You will have to put all of that on shared servers like databases, memcache etc. This will allow you to freely bring up or bring down your WebApp JVMs as per user load at any given time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM