如何减少MySQL连接时间

发布于 2024-09-10 09:27:37 字数 389 浏览 2 评论 0原文

我有一个 JSP 页面。它曾经运行良好,但在系统团队升级 Solaris 10 操作系统服务器后,它变得非常慢(加载需要 15 秒)。

我检查了该页面中的所有查询,每个查询都工作正常。事实上它们都是非常简单的查询。并且每个相关表中只有大约300个条目。

唯一特别的是,该页面中有大约 60 个连接。在发现速度非常慢后,我设法将连接数减少了 30 个。经过此优化后,加载时间减少至 6 秒。但是,还是很慢!更糟糕的是,如果我不想重新构建一半的应用程序,我将无法再减少连接。

另一个 JSP 页面(不在同一个应用程序中)运行良好,但现在也变得很慢。它只有 1 个连接,但此页面对时间非常敏感。因此我可以看到它变得更慢。

谁能告诉我如何配置 mysql 或/和 tomcat 来减少 mysql 连接时间?

I have a JSP page. It used to work well but it becomes very slow (15 seconds to load) after the Systems team upgraded the Solaris 10 OS server.

I checked all the queries in that page and every query works fine. In fact they are all very simple queries. And there are only about 300 entries in each related table.

The only special thing, there were about 60 connections in that page. I managed to decrease the connections by 30 after I found it is very slow. After this optimization the loading time decreased to 6 seconds. But, still very slow! And what's worse, I am unable to decrease the connections any more if I don't want to re-construct half of the application.

Another JSP page (not in the same application) worked well but now it becomes slow too. It has only 1 connection but this page is very time sensitive. Thus I can see it becomes slower.

Can anyone tell me how to configure mysql or/and tomcat to decrease mysql connection time?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无畏 2024-09-17 09:27:37

当你说“查询”时,你说的是“连接”吗?或者您是否为每个查询创建一个新的数据库连接?你不应该那样做。在 Tomcat 应用服务器中,您应该使用连接池,这将大大减少连接的开销。

另一个常见问题是 MySQL 服务器尝试从 IP 地址解析客户端的主机名。这称为 DNS 主机名解析,在建立新连接时它可能会产生大量开销。您可以将 MySQL 服务器配置为跳过 DNS 主机名解析,而无需有很多缺点。

Are you saying "connection" when you mean "query"? Or are you making a new database connection for each query? You should not do that. In a Tomcat app server, you should use connection pooling, which will reduce the overhead of connections a lot.

Another common issue is that the MySQL Server tries to resolve your client's hostname from its IP address. This is called DNS hostname resolution, and it can be the source of a lot of overhead when making a new connection. You can configure your MySQL Server to skip DNS hostname resolution without much downside.

何必那么矫情 2024-09-17 09:27:37

为什么每一页加载时要建立多个数据库连接?这不应该是一般情况。建立一个连接并将其用于该页面的所有呈现。

Why are you making more than one database connection per page load? That should not be the general case. Make one connection and use it for all the rendering of that page.

老旧海报 2024-09-17 09:27:37

您如何在连接字符串上引用服务器?您使用的是“localhost”还是其他东西?例如,尝试将其替换为“127.0.0.1”,这将跳过名称解析。

How are you referencing the server on your connection string? Are you using "localhost" or something? Try to replace that by "127.0.0.1" for instance, which will skip the name resolution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文