php - Handling hundreds of simultaneous requests in rails -
i writing ruby on rails application , 1 of important featuers of website live voting. expect 10k voting requests in little 1 minutes. along other requests means getting ton of requests.
my initial idea set server use apache + phusion, however, voting i'm thinking writing php script on side , write/read information in memcached. data needs persist 15 minutes, writing database 10,000 times in 1 minute seems pointless. need mark ip of user don't vote twice being complicated in memcached.
if has suggestions or ideas make work best possible, please help.
if you're architecting app kind of massive influx, you're going need strip down essential components of absolute minimum.
using full rails stack kind of intensity isn't practical, nor necessary. better build thin rack layer handles voting making direct db calls, skipping orm, being wrapper around insert
statement. sinatra , sequel, serves efficient query generator, might with.
you should sure tune database properly, plus run many load tests against sure performs expected, healthy margin higher loading.
making 10,000 db calls in minute isn't big deal, each call take fraction of millisecond on tuned stack. memcached offer higher performance if results not intended permanent. memcached has atomic increment operator you're looking when tabulating votes. redis capable temporary store.
another idea scrap db altogether , write persistent server process speaks simple json-based protocol. eventmachine great throwing these things if you're committed ruby, nodejs if you're willing build out specialized tally server in javascript.
10,000 operations in minute achievable on modest hardware using specialized server processes without overhead of full db stack.
you have sure scope defined can test , heavily abuse implementation prior deploying it.
since you're describing is, @ core, equivalent hash lookup, essential code simply:
contest = @contest[contest_id] unless (contest[:voted][ip]) contest[:voted][ip] = true contest[:votes][entry_id] += 1 end
running several hundred thousand times in second entirely practical, overhead wrapping json layer around it.
Comments
Post a Comment