简体   繁体   English

每秒处理大量请求和数据库的Ruby on Rails性能

[英]Ruby on Rails performance on lots of requests and DB updates per second

I'm developing a polling application that will deal with an average of 1000-2000 votes per second coming from different users. 我正在开发一个轮询应用程序,它将平均每秒处理来自不同用户的1000-2000票。 In other words, it'll receive 1k to 2k requests per second with each request making a DB insert into the table that stores the voting data. 换句话说,它将每秒接收1k到2k个请求,每个请求都将一个DB插入存储投票数据的表中。

I'm using RoR 4 with MySQL and planning to push it to Heroku or AWS. 我正在将RoR 4与MySQL结合使用,并计划将其推送到Heroku或AWS。

What performance issues related to database and the application itself should I be aware of? 我应注意哪些与数据库和应用程序本身有关的性能问题?

How can I address this amount of inserts per second into the database? 如何处理每秒插入数据库的数量?

EDIT 编辑

I was thinking in not inserting into the DB for each request, but instead writing to a memory stream the insert data. 我在考虑不要将每个请求插入数据库,而是将插入数据写入内存流。 So I would have a scheduled job running every second that would read from this memory stream and generate a bulk insert, avoiding each insert to be made atomically. 因此,我将有一个调度的作业每秒运行一次,该作业将从此内存流中读取并生成大容量插入,从而避免了每次插入都是原子方式进行的。 But i cannot think in a nice way to implement this. 但是我无法以一种很好的方式来实现这一目标。

While you can certainly do what you need to do in AWS, that high level of I/O will probably cost you. 尽管您当然可以在AWS中完成所需的工作,但高水平的I / O可能会使您付出代价。 RDS can support up to 30,000 IOPS; RDS最多可支持30,000 IOPS; you can also use multiple EBS volumes in different configurations to support high IO if you want to run the database yourself. 如果您想自己运行数据库,还可以使用不同配置的多个EBS卷来支持高IO。

Depending on your planned usage patterns, I would probably look at pushing into an in-memory data store, something like memcached or redis, and then processing the requests from there. 根据您计划的使用模式,我可能会考虑将其放入内存中的数据存储(如memcached或redis),然后从那里处理请求。 You could also look at DynamoDB, which might work depending on how your data is structured. 您还可以查看DynamoDB,它的工作方式取决于数据的结构。

Are you going to have that level of sustained throughput consistently, or will it be in bursts? 您将要始终保持这种水平的持续吞吐量,还是会突然爆发? Do you absolutely have to preserve every single vote, or do you just need summary data? 您是否绝对必须保留每一票,还是只需要摘要数据? How much will you need to scale - ie will you ever get to 20,000 votes per second? 您需要扩展多少-即,您将每秒获得20,000票吗? 200,000? 20万?

These type of questions will help determine the proper architecture. 这些类型的问题将有助于确定适当的体系结构。

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

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