小型应用程序中的连接池
我有一些关于连接池和最佳实践的简单问题。 我正在计划和编写一个依赖 MySQL 数据库的小型应用程序。在此应用程序中,我使用可以创建连接的模块和插件。该应用程序可以直接访问 MySQL 数据库,并且它可能是连接到该数据库的唯一客户端。
这是我的第一个问题:连接池有意义吗?它无关紧要还是我应该禁用它?您的经验是什么?
另一方面,在我的公司,我们开发了另一种软件,它有一个 MySQL 数据库服务器和许多客户端。每个客户端都可以打开多个窗口,其中多个连接可以处于活动状态。该软件很可能会使用我的新应用程序的基本概念。客户端直接与数据库连接。所以我想编写一个处理池和组织连接的服务器应用程序会很有意义,对吗?让每个客户端使用自己的连接池有多大意义?我们谈论的是具有 1-10 个连接的 1-50 个客户端。
您认为编写一个小型服务器应用程序来处理连接池是最好的吗?
我这么问是因为我真的不知道连接池何时有意义、何时不有意义以及如何处理它中小型客户端应用程序。我正在寻找您的一些经历。 :) 我希望问题不会太尴尬。 ^^
问候,
Simon
P.S.:这是一个基于 Windows 的应用程序。不是网络服务。
I've got a few simple questions about connection pooling and best practices.
I'm planning and writing a small application which relies on a MySQL database. In this application I use modules and plug-ins which can create connections. The application has direct access to the MySQL database and it will probably be the only client connecting to the database.
Here are my first questions: Will connection pooling make sense? Is it irrelevant or should I disable it? What are your experiences?
On the other hand in my company we develop another software which has one MySQL database server and many clients. Every client can open multiple windows in which multiple connections can be active. There is a good chance that this software will be using the basic concept of my new application. The clients connect directly with the database. So I guess it would make a lot of sense to write a server application which handles the pooling and organizes the connections, am I right? How much sense would it make to let every client use it's own connection pool? We're talking about 1-50 clients with 1-10 connections.
Do you think it's the best to write a small server application to handle the connection pooling?
I'm asking because I don't really know when connection pooling makes sense and when not and how to handle it with small and medium sized client applications. I'm looking for some input of your experiences. :) I hope the questions is not to awkward. ^^
Greetings,
Simon
P.S.: It's a windows based application. Not a web service.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
连接池将为您提供额外的性能,实际上,如果没有它,即使对于小型应用程序,性能也可能是一个问题(这取决于调用、数据等的数量)。
考虑正确处理您的连接,以避免“达到最大池大小”错误和超时。一个好的做法是像这样处理您的连接:
使用保证连接将被正确关闭/处置。查看这篇文章,其中提供了一些可应用于 MSSQL 或 MySQL 的技巧。
还要考虑存储过程的使用。希望这可以帮助您入门。
Connection pooling will give you extra performance, actually without it performance may be an issue even for a small application (it depends on the number of calls, data, etc).
Consider properly handling your connections in order to avoid 'max pool size reached' errors and timeouts. A good practice is to handle your connection like this:
using guaranties than the connection will be properly closed/disposed. Check this article that provides some tips that can be applied either for MSSQL or MySQL.
Consider also the use of stored procedures. Hope this help you getting started.