1

I have a couple of tables:

media: id, name, score
media_rating: id, value, media_id, user_id

A user performs a rating on the site and the system:

  1. Create a news media_rating record
  2. Increase the score on the appropriate media by the value of the media_rating

Problem: There are media ratings coming in at 500 to 1000 new records per second. I need to read from media to give users media to rate, but I feel like the table is being completely bombarded with updates on score from all of the new media_rating's being created. Requests are failing like crazy.

How can I make this thing scale?

1
  • Can you describe your tables? Are you adding a new record in the ratings table for each rating, or incrementing a counter row integer column for each resulting combination of media and rating level? I only ask because you adding 43 million rows per day in the former case. Jun 6, 2012 at 23:48

3 Answers 3

0

Perhaps avoiding MySQL all together might be the answer. I've had great success in the past doing similar things using Redis (http://redis.io/). Have a read of the documentation (http://redis.io/documentation), it might lead you in the right direction.

0

Your second step is in fact not necessary, as you have the data already available with a simple query (something like SELECT COUNT(*) FROM media_rating WHERE media_id = x). Although this saves you from a lot of updates, it could create another problem, as every time you want your users to present the rating you'd need a count. A count isn't necessary extensive, so it might save you some (as you have to query the database anyway when retrieving the current rating). If it still gives you problems, you could 'delay' the rating count; update the score only once in a while (with either a cronjob or poormans-cron)

0

Treating this more like a web analytics problem may lead you down some helpful paths... Such as recording only a sampling of the actual ratings...

What is the best way to count page views in PHP/MySQL?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.