存储增量数字的最佳方式?

发布于 2024-11-30 07:42:27 字数 254 浏览 0 评论 0原文

我正在为一个相对较大的网站实现投票系统,我想知道应该在哪里存储投票计数。主要问题是,将它们存储在主数据库中会给它带来很大的压力,因为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

罗罗贝儿 2024-12-07 07:42:27

你能接受一定程度的选票损失吗?如果是这样,您可以采用混合解决方案。每模 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.

猥琐帝 2024-12-07 07:42:27

我刚刚运行了这个,这基本上是 sqlite 示例文档除了插入 5000 行:

import time
import sqlite3

conn = sqlite3.connect('example')

c = conn.cursor()

# Create table
c.execute('''create table stocks 
    (date text, trans text, symbol text, qty real, price real)''')

print time.time()

for i in xrange(5000):

    # Insert a row of data
    c.execute("""insert into stocks
              values ('2006-01-05','BUY','RHAT',100,35.14)""")


# We can also close the cursor if we are done with it
# Save (commit) the changes
conn.commit()
c.close()

print time.time()

在我的笔记本电脑上的十分之四秒内。

绝大多数时间都花在数据库提交上。因此,只要您不太频繁地向数据库提交(每隔几秒或更短一次),SQLite 就可以轻松处理每秒 5000 票的负载。

每分钟 4000 票根本不会分阶段,只要你不在每次投票后都做出承诺。

I just ran this, which is basically the sqlite example from the docs except inserting 5000 rows:

import time
import sqlite3

conn = sqlite3.connect('example')

c = conn.cursor()

# Create table
c.execute('''create table stocks 
    (date text, trans text, symbol text, qty real, price real)''')

print time.time()

for i in xrange(5000):

    # Insert a row of data
    c.execute("""insert into stocks
              values ('2006-01-05','BUY','RHAT',100,35.14)""")


# We can also close the cursor if we are done with it
# Save (commit) the changes
conn.commit()
c.close()

print time.time()

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.

一个人的旅程 2024-12-07 07:42:27

MySQL 不太擅长处理大量简单查询

您的 MySQL 服务器中可能存在严重配置错误的内容。 MySQL 应该能够轻松处理每分钟 4000 个查询。 MySQL 有每秒处理超过 25k INSERT 的基准。

MySQL isn't very good at handing lots and lots of simple queries

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.

站稳脚跟 2024-12-07 07:42:27

您可以查看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)

旧时模样 2024-12-07 07:42:27

Mongodb 可以很好地工作。因为它可以更快,或者 Google App Engine 是为了扩展而设计的。

Mongodb can work well.Since it can be faster or Google App Engine was designed to scale.

浅笑轻吟梦一曲 2024-12-07 07:42:27

如果您喜欢 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文