存储增量数字的最佳方式?
我正在为一个相对较大的网站实现投票系统,我想知道应该在哪里存储投票计数。主要问题是,将它们存储在主数据库中会给它带来很大的压力,因为 MySQL 不太擅长处理大量的简单查询。
到目前为止,我最好的选择是使用 memcached,因为它似乎非常适合此任务(非常快且面向键/值)。此解决方案的唯一问题是 memcached 是非持久性的,并且没有简单的方法来保存这些值。
是否有专门为此任务设计的东西,最好带有 Python 后端?
I'm implementing a voting system for a relatively large website and I'm wondering where should I store the vote count. The main problem is that storing them in the main database would put a lot of strain on it, as MySQL isn't very good at handing lots and lots of simple queries.
My best option so far is to use memcached
as it seems perfect for this task (very fast and key/value oriented). The only problem with this solution is that memcached
is non-persistent and there is no easy way of saving these values.
Is there something that is specifically designed for this task, preferably with a Python back end?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
你能接受一定程度的选票损失吗?如果是这样,您可以采用混合解决方案。每模 100(10,某物),用当前的
memcache
值更新 SQL 数据库。如果需要,您还可以定期进行脚本扫描和更新。Can you accept some degree of vote loss? If so, you can do a hybrid solution. Every modulo 100 (10, something), update the SQL database with the current
memcache
value. You can also have a periodic script scan and update if required.我刚刚运行了这个,这基本上是
sqlite
示例文档除了插入 5000 行:在我的笔记本电脑上的十分之四秒内。
绝大多数时间都花在数据库提交上。因此,只要您不太频繁地向数据库提交(每隔几秒或更短一次),SQLite 就可以轻松处理每秒 5000 票的负载。
每分钟 4000 票根本不会分阶段,只要你不在每次投票后都做出承诺。
I just ran this, which is basically the
sqlite
example from the docs except inserting 5000 rows:in four tenths of a second on my laptop.
The vast majority of that time is spent in the database commit. So as long as you don't commit to the database too often (once every couple of seconds or less), SQLite can easily handle a load of 5000 votes per second.
4000 votes per minute won't phase it at all, so long as you're not committing after every vote.
您的 MySQL 服务器中可能存在严重配置错误的内容。 MySQL 应该能够轻松处理每分钟 4000 个查询。 MySQL 有每秒处理超过 25k INSERT 的基准。
You may have something drastically misconfigured in your MySQL server. MySQL should easily be able to handle 4000 queries per minute. There are benchmarks of MySQL handling over 25k INSERTs per second.
您可以查看CUBRID。我还没有尝试过,但看起来很有希望,他们宣传几乎 100% MySQL 兼容性,还有一些不错的东西,比如
SELECT INCR(field)
You can have a look at CUBRID. I haven't tried it, but it seems promising, they advertise almost 100% MySQL compatibility, plus some nice stuff like
SELECT INCR(field)
Mongodb
可以很好地工作。因为它可以更快,或者Google App Engine
是为了扩展而设计的。Mongodb
can work well.Since it can be faster orGoogle App Engine
was designed to scale.如果您喜欢 memcached,但不喜欢它不持久保存数据,那么您应该考虑使用 Membase。 Membase 基本上是 memcached,以 sqlite 作为持久层。它非常容易设置并支持 memcached 协议,因此如果您已经设置了 memcached,则可以使用 Membase 作为替代品。
If you like memcached but don't like the fact that it doesn't persist data then you should consider using Membase. Membase is basically memcached with sqlite as the persistence layer. It is very easy to set up and supports the memcached protocol so if you already have memcached set up you can use Membase as a drop in replacement.