English 中文(简体)
如何优化数据库连接的数量?
原标题:How to optimize number of database connections?

We have a Java (Spring) web application with Tomcat servlet container. We have a something like blog. But the blog must load its posts dynamically with Ajax. The client s ajax script checks for new posts every second. I.e. Ajax must ask the server for new posts every second and it will be very heavy for database.

But what if we have hundreds of thousands connects simultaneously? I think that we must retrieve all posts with cron every second and after that save it somewhere. But where? The main idea is to unload the database. Any ideas about architecture? Thanks in advance!

最佳回答

根据具体情况,还有其他更优化的轮询架构:

长时间轮询

长时间轮询 is a variation of the traditional polling technique and allows emulation of an information push from a server to a client. With long polling, the client requests information from the server in a similar way to a normal poll. However, if the server does not have any information available for the client, instead of sending an empty response, the server holds the request and waits for some information to be available. Once the information becomes available (or after a suitable timeout), a complete response is sent to the client. The client will normally then immediately re-request information from the server, so that the server will almost always have an available waiting request that it can use to deliver data in response to an event. In a web/AJAX context, long polling is also known as Comet programming.

长轮询

Example of Implementations of this technology: Push Server

您还可以使用observer模式来注册请求,并在更新完成时通知它们。

问题回答

成千上万的并发用户每秒钟都在我们的网站上进行投票,这产生了巨大的流量。如果你真的期望这样的负载,你就必须相应地设计你的平台,可能是通过集群多个web、应用程序和数据库服务器。

请记住,对于数据库连接池,您不需要每个用户都有一个数据库连接。

我对Tomcat不太熟悉,但在WebSphere中,我们可以设置连接池来准备一定数量的连接。

此外,你主要担心的是读还是写的数量相同?

此外,您可能还希望根据地区等对数据库进行“拆分”。这样,整个数据库就不会有单一的重负载,但可以进行拆分,甚至实现负载平衡。

还有“NoSQL”数据库也需要研究。也许需要考虑一下。只是帮忙的想法。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签