我对并发MySQL连接感到困惑 [英] I'm confused about concurrent MySQL connections

查看:85
本文介绍了我对并发MySQL连接感到困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我在Mysql上读了一本书,它说可以访问数据库的并发用户数是有限制的.

So, I read a book in Mysql and it says that there's a limit on how many concurrent users that can access a database.

这是否意味着如果我有2万用户同时在Web应用程序中浏览,我的Web应用程序将无法在数据库中加载数据?因为我的Web应用程序每次访问我的网站时都会访问数据库.

Does that mean that If I have 20k users browsing in my web application concurrently, my web application will fail to load the data in my database? Because my web application is accessing the database every time my website loads.

推荐答案

2万名用户完全同时加载页面?相当多-而且您的网络服务器本身可能不会接受那么多并发请求(例如,Apache通常只接受200至400个并行请求).

20k users loading a page at the exact same time ? That's quite a lot -- and your webserver will probably not accept that many concurrent requests itself (For example, Apache generally accepts only between 200 and 400 parallel requests).

连接限制是完全相同的时间可以连接到数据库的最大用户数-如果每个页面需要生成100毫秒,则仅一个用户将被连接少于100毫秒.
如果您只是在需要执行第一个SQL查询时连接数据库,而在上一个SQL查询之后立即断开连接,则可以减少Web服务器连接到数据库的时间.

The connection limit is the maximum number of users that can be connecter to your database at the exact same time -- if each page needs 100 ms to be generated, one user will only be connected for less than 100 ms.
And if you connect to your database just when you need to do your first SQL query, and disconnect immediately after your last SQL query, this can reduce the time during which your Webserver is connected to the DB.

如果您的用户正在阅读您网站上的内容,则可以认为他们会:

If you have users reading content from your website, you can consider they will :

  • 加载页面(可能在您的服务器上为100毫秒)
  • 什么都没做,只需要阅读几分钟(服务器上绝对不需要任何资源)
  • Load a page (maybe 100 ms on your server)
  • Do nothing but read for a couple of minutes (which takes absolutly no resource on your server)


附带说明:在获得20k个并发连接(这意味着每秒约20,000个连接!)之前,要花相当长的时间,您可能不得不处理几个与缩放相关的问题...


As a sidenote : quite a long time before getting 20k concurrent connections (which means about 20,000 connections per second or so !), you'll probably have to deal with several scaling-relating problems...

这篇关于我对并发MySQL连接感到困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆