在 Tomcat 上使用 MySQL 池化PreparedStatement
当将Tomcat与MySQL一起使用时,Tomcat数据源配置中的poolPreparedStatements设置(我相信来自DBCP)和Connector/J之间的关系是什么 cachePrepStmts 设置?最佳配置是多少?
When using Tomcat with MySQL, what is the relationship between poolPreparedStatements setting in Tomcat DataSource configuration (I believe coming from DBCP) and Connector/J cachePrepStmts setting? What's the optimal configuration?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
poolPreparedStatements 是 Tomcat JDBC 连接池的设置,cachePrepStmts 是 Connector/J 的设置,用于告诉 MySQL 缓存准备好的语句。两种完全不同的东西。 cachePrepStmts 是针对每个连接的设置,但 Connector/J 并不关心它是连接到数据库连接池还是直接连接到 MySQL,但 cachePrepStmts 在持久连接(例如连接池)方面效果最佳。将cachePrepStmts 与连接池一起使用是最佳配置。在 Tomcat 中使用 poolPreparedStatements 会打开一罐内存管理蠕虫(查看 Tomcat 文档了解此设置,您就会看到)。实际上,最好让 MySQL 缓存准备好的语句并让 Tomcat 池化连接,而不是试图让一个人做另一个人的工作。
poolPreparedStatements is a setting for the Tomcat JDBC connection pool and cachePrepStmts is a setting for Connector/J to tell MySQL to cache prepared statements. Two completely different things. cachePrepStmts is a per connection setting, but Connector/J doesn't concern itself with whether it's connecting to a database connection pool or to MySQL directly, yet cachePrepStmts works at it's best with persistent connections (e.g. connection pools). To use cachePrepStmts with a connection pool is the optimal configuration. Using poolPreparedStatements in Tomcat is to open a can of memory management worms (check out the Tomcat docs for this setting and you'll see). Really, it's best to let MySQL cache the prepared statements and let Tomcat pool the connections and not try to have one do the other's job.