即使在使用连接池后,如何处理太多的并发连接? [英] How to handle too many concurrent connections even after using a connection pool?

查看:254
本文介绍了即使在使用连接池后,如何处理太多的并发连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景



假设您有拥有大量流量的网站或应用程式。即使有数据库连接池,性能也会受到真正的打击(网站/应用甚至可能崩溃),因为并发连接太多。



问题



有人处理此问题的选择是什么? p>

我的想法



我认为有人可能会创建多个数据库在不同的机器上,虽然我不确定这是必要的),每个具有相同的信息,并同时更新,这将授予单个数据库的原始数量的连接的倍数。但是如果数据库很大,似乎不是一个非常可行的解决方案。

解决方案

一个坚定的建议,但是可以做的完整列表如下:




  • 数据库群集:适合对于您不想更改您的应用程序层和数据库的情况是所有你触摸。有多少可以从数据库集群出来的限制。如果您的请求量持续增长,这个解决方案最终也会失败。但是好消息是,你已经拥有了在普通单实例MySQL中已经拥有的所有功能。

  • Sharding :因为你的问题是标记MySQL,它不支持自己的分片,如果你想使用这个解决方案,你需要在你的应用程序层实现它。在此解决方案中,您将数据分散到多个数据库(最好在多个MySQL实例在单独的硬件上)。您有责任找到保存您指定数据的适当数据库。它是有史以来最有效的解决方案之一,但并不总是可行的。其最大的缺陷是,在两个或多个数据库之间分散的数据不能包含在事务中。

  • 复制:根据您的方案,数据库复制并在其上具有您的数据的副本。这样,您可以连接到它们而不是主数据库,并减少它的负载。默认复制定义是主/从方案,其中数据流是单向的,从主机到从机。因此,您可以在从服务器上进行的更改将应用​​于从服务器时,它们不会影响主服务器。但是还有一个主/主复制配置,其中数据流以两种方式。然而,你不能假定原子完整性在两个主机之间的并发数据更改。最终,如果您打算在主/从模式下使用它,并使用从属进行只读访问,则此解决方案最为有效。

  • 缓存:也许解决方案不应该包括在这里,但因为你的stem不拒绝它,这里它去。减少数据库负载的一种方法是一旦提取就缓存其数据。如果提取数据是昂贵的,这种解决方案可能是有益的。有很多缓存服务器,如 memcached redis

  • 其他存储引擎:您可以随时切换到更高性能的引擎,如果您的当前一个不提供你所需要的。当然这只是可行的,如果你的需要允许你。现在有NoSQL引擎,比RDBMS更高性能,它支持本地分片,你可以以最小的努力线性扩展它们。还有基于Lucene的解决方案,有强大的全文搜索功能,为您提供相同的自动分片。事实上,你应该使用传统RDBMS的唯一原因是事务的原子行为。但是如果交易不是必须的,那么比RDBMS有更好的解决方案。


Scenario

Say you have a website or app that has tons of traffic. And even with a database connection pool, performance is taking a real hit (the site/app may even be crashing) because there are too many concurrent connections.

Question

What are someone's options for dealing with this problem?

My thoughts

I was thinking someone with this problem could create multiple databases (possibly on different machines although I'm not sure that's necessary), each with the same information and updated at the same time, which would grant a multiple of the original number of connections for a single database. But if the database is large that doesn't seem like a very viable solution.

解决方案

The stem is not specific enough to give a firm suggestion, but the complete list of what could be done is as follow:

  • Database cluster: Suitable for situations where you don't want to change your application layer and database is all you touch. There's a limit on how much you can get out of a database cluster. If your request volume keeps on growing, this solution will fail as well eventually. But the good news is that you've got all the functionality you've already had in an ordinary single-instance MySQL.
  • Sharding: Since your question is tagged with MySQL, and it does not support sharding on its own, if you want to use this solution you need to implement it in your application layer. In this solution you'll scatter your data over multiple databases (preferably in multiple MySQL instances on separate hardware) logically. It will be your responsibility to find the appropriate database holding your designated data. It's one of the most effective solutions ever but it's not always feasible. Its biggest flaw is that data scattered among two or more databases can not be included within a transaction.
  • Replication: Depending on your scenario you might be able to incorporate database replication and have copies of your data on them. This way you can connect to them instead of the master database and reduce the load on it. The default replication definition is master/slave scenario in which data flow is one way, from master to the slave. So changes you might make on the slave while will be applied on the salve, they won't be affecting the master. But there is also a master/master replication configuration in which data flow is in both ways. Yet you can not assume atomic integrity for concurrent data changes among both masters. In the end this solution is most effective if you plan to use it in master/slave mode and using slaves for read-only access.
  • Caching: Perhaps this solution should not be included here but since your stem does not reject it, here it goes. One of the ways to reduce database load is to cache its data once extracted. This solution can be beneficial specially if extracting data is expensive. There are many cache servers out there, like memcached or redis. This way you can omit so many of the database connections but only for extraction of data.
  • Other storage engines: You can always switch to more performant engines if your current one does not provide you with what you need. Of course this is only feasible if your needs allow you to. Nowadays there are NoSQL engines, much more performant than RDBMS, which support sharding natively and you can scale them linearly with minimum effort. There are also Lucene based solutions out there with powerful full-text search capabilities providing you with the same automatic sharding. In fact the only reason why you should be using a traditional RDBMS is the atomic behavior of transactions. But if transactions are not a must, there are much better solutions than RDBMS.

这篇关于即使在使用连接池后,如何处理太多的并发连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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