简体   繁体   English

随着并行会话数的增加,如何缩放基于Java的Web应用程序?

[英]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. 我有一个基于Java的(弹簧/休眠)Web应用程序,用户可以在其中执行6个不同的任务。 Each task creates a thread pool of 30 threads. 每个任务创建一个包含30个线程的线程池。 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. 多个用户可以同时登录该应用程序并执行这6个任务中的任何一个。

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. 这里需要担心的是,该应用程序最终将处于OOM中,并且有大量线程处于活动状态。

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. 一旦开始增加用户数量,最终将耗尽计算机或JVM可提供的资源。 In your case it seems to be threads which translates to memory and CPU. 在您的情况下,似乎是线程转换为内存和CPU。

You will need to use more machines and JVM instances. 您将需要使用更多的机器和JVM实例。 You may need stateless architecture to do so. 您可能需要无状态架构。

User Browsers --> Load Balancer --> Farm of stateless WebApp servers --> Database 用户浏览器- >负载均衡器- >无国籍Web应用程序服务器农场 - >数据库

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. 在此体系结构中,您需要注意的事情是您不应在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. 您必须将所有这些都放在共享服务器上,例如数据库,内存缓存等。这将允许您在任何给定时间根据用户负载自由地启动或关闭WebApp JVM。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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