数据库连接数,有多少!
好吧,我知道问我应该建立多少个数据库写连接是相当模糊的。
尽管如此,我还是以不同的方式把这个问题放在这里。假设我有 10 个彼此独立的表。
我的意思是写入一个表并不强制写入另一个表。可以以相等的概率写入任何表中。
应考虑哪些因素来决定应向数据库建立多少个写入连接。我想在内存中创建这些连接(连接对象)并在需要时使用它。
Well, I understand this is quite vague to ask how many db write connections should I make.
Still, I'm putting this question here, but in a different way. Lets say I've 10 tables which are independent of each other.
I mean writing into one table does not mandate writing into other. The can be written into any of the tables with equal probabilitites.
What factors should be taken in mind to decide how many write connecttions should I make to a DB. I want to create these connections (connection objects) in memory and use it whenever required.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,只要您将数据库操作批量保存在一起,就不会有太大影响。
就我个人而言,我有一个 DBRead 函数,用于创建连接、执行 SQL 语句、获取 DataTable (C#) 并关闭连接。通常每个页面渲染调用 3-8 次,考虑到我大量使用 AJAX 和客户端数据计算(很少甚至没有服务器端分页),这并不算多。
如果数据库服务器位于另一台计算机上,甚至在您的网络之外,这可能会有所不同,因为延迟时间会增加,但通常您只需扔掉它们并重新创建它们就可以了。
Typically it shouldn't matter much as long as you keep your database operations batched together.
Personally I have a
DBRead
function that creates a connection, executes the SQL statement(s), gets aDataTable
(C#) and closes the connection. It is typically called 3-8 times per page render, which isn't that much considering I make heavy use of AJAX and client-side computing of data (little to no server side paging).This may be different if the database server is on another computer or even outside your network, as the latency times add up, but typically you should be fine just throwing them away and recreating them.