简体   繁体   English

NodeJS + MySql 与大并发访问

[英]NodeJS + MySql and large concurrent access

So I have been writting this NodeJS Quiz App.所以我一直在写这个 NodeJS Quiz App。 At first we are not expecting that much users, but as time goes by we are looking at about ~50000 potential registered users.起初我们并没有期望有那么多用户,但随着时间的推移,我们会看到大约 50000 名潜在注册用户。 Considering the DB of choice iss MySql, and also considering not all registered users are going to be logged in at the same time, what is the maximum number of concurrent MySQL connections possible?考虑到选择的数据库是 MySql,同时考虑到不是所有的注册用户都会同时登录,最大并发 MySQL 连接数是多少? Also, how much RAM and CPU would I need to host this app?另外,我需要多少内存和 CPU 来托管这个应用程序?

When you are using node.js, you can simply use connection pooling, there is no obvious downside to pooling but you are establishing much less connection (and less overhead).当您使用 node.js 时,您可以简单地使用连接池,池没有明显的缺点,但是您建立的连接要少得多(并且开销也更少)。

In addition, it all goes down to how much query is actually executed and how much execution time they need, here are some make up numbers:此外,这一切都取决于实际执行了多少查询以及他们需要多少执行时间,这里有一些补充数字:

Let's say if 50k users all go online at the same time, and each user makes 1 interaction per 5s and takes 10ms DB time to execute, then 50k * 10ms / 5s = 100 concurrent connection needed.假设有 50k 个用户同时在线,每个用户每 5s 进行 1 次交互,执行需要 10ms DB 时间,则需要 50k * 10ms / 5s = 100 个并发连接。

Of course you need to factor in some real numbers, and read-to-write ratio matters a lot (read can potentially run in parallel), and cache can help a lot if reading makes up large number of queries.当然,您需要考虑一些实数,读写比率很重要(读取可能并行运行),如果读取构成大量查询,则缓存可以提供很大帮助。

All in all, you are unlikely to need much if all you do is some simple select and insert per interaction.总而言之,如果您所做的只是在每次交互中进行一些简单的选择和插入,那么您不太可能需要太多。

PS This post gave some interesting number: with connection pooling, 5k connection = 100k concurrent user. PS 这篇文章给出了一些有趣的数字:使用连接池,5k 连接 = 100k 并发用户。 Of course he/she didn't mention his/her load type, but you can see that (concurrent / connection threads) can be up to tens and hundred when connection pool is in place.当然他/她没有提到他/她的负载类型,但是你可以看到(并发/连接线程)在连接池到位的情况下可以达到数十和数百。

you can set mySQL the max global connection up to 10,00,000.您可以将 mySQL 的最大全局连接设置为 10,00,000。 and for hardware requirement below link can help you.对于硬件要求,下面的链接可以帮助您。

https://www.percona.com/blog/2019/02/25/mysql-challenge-100k-connections/ https://www.percona.com/blog/2019/02/25/mysql-challenge-100k-connections/

Hope you get your answers if not let me know.如果不让我知道,希望你能得到你的答案。

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

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