简体   繁体   English

我如何知道连接池和准备语句是否正常工作?

[英]How do I know Connection Pooling and Prepared Statements are working?

I have been developing a web application for almost a year which I had started in college. 我已经在大学开始了近一年​​的网络应用程序开发。 After finishing, I made some changes to the database code that I had written during college. 完成后,我对大学期间编写的数据库代码进行了一些更改。 I used simple JDBC when I was in college, without the use of connection pooling and prepared statements. 我在大学时使用简单的JDBC,没有使用连接池和预处理语句。 In the past month, I have realized the potential, and need to use connection pooling, and prepared statements because of the increase in data being queried and used. 在过去的一个月里,由于查询和使用的数据增加,我意识到了潜力,并且需要使用连接池和准备好的语句。

I have implemented the connection pooling, but have not really noticed an increase in performance. 我已经实现了连接池,但没有真正注意到性能的提高。 If there was an increase in performance, then my question would be answered, but how can I validate that connection pooling and prepared statements are being used properly? 如果性能有所提高,那么我的问题就会得到解答,但是如何验证连接池和准备好的语句是否正确使用?

I think prepared statement is more important from a security than a performance standpoint. 我认为预备声明从安全性而非性能角度来看更为重要。 If you are using them cool, you really should be. 如果你使用它们酷,你真的应该。 As long as 100% of your SQL is a prepared statement, you are "using them right"... 只要您的SQL的100%是准备好的语句,您就“正确使用它们”......

Connection pooling is something you won't notice under light load. 连接池是轻负载时您不会注意到的。 1 or 2 or 10 users, you will likely see 0 or near 0 difference. 1或2或10个用户,您可能会看到0或接近0的差异。 You would need to create some kind of load testing test to simulate 100s of simultaneous users, then compare performance with and without pooling. 您需要创建某种负载测试测试来模拟100个并发用户,然后比较使用和不使用池的性能。

You won't see a performance improvement if opening and closing connections wasn't rate-limiting. 如果打开和关闭连接不是速率限制,您将看不到性能改进。 Try looking at your database's profiling tools for a list of open connections. 尝试查看数据库的分析工具以获取打开的连接列表。 If you see open connections from your process when you have ostensibly closed them, the interface layer is doing connection pooling. 如果在表面上关闭它们时看到来自进程的打开连接,则接口层正在进行连接池。

See also this other SO question on forcing a pooled connection to drop. 另请参阅另一个关于强制池连接丢弃的问题。

(Caveat:I use ADO and ADO.NET; JDBC might behave differently.) (警告:我使用ADO和ADO.NET; JDBC可能表现不同。)

You ask the connection pool for statistics to see if it works. 您向连接池询问统计信息是否有效。 If the connection pool library does not provide statistics, find a better library. 如果连接池库未提供统计信息,请查找更好的库。

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

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