tags:

views:

36

answers:

2

Im wondering if I should bother changing my system.

Currently when a video is viewed, it runs a query that does

UPDATE table SET hits=hits+1 WHERE id = $id.

very simple, except they appear in the slow query log all the time, sometimes with 3-4 seconds of query_time.

What if I INSERT every view as a new row into a memory table, and commit changes to DB with cron every hour? Will there be a significant difference in performance? Are there any alternatives?

+1  A: 

You might want to check you have an index on id as that update should not take many seconds. This is about the simplest update you can do so you can't really speed it up.

If it does I think you have other problems with your database.

Mark
yah I got index on there, yet as the traffic increased, there is a significant increase in those queries (obviously). The site is currently doing around 100k uniques per day.... with maybe 500,000 page views.
Yegor
Still not a very large volume - what does the query actually use the index and is anything else slow?
Mark
A: 

I would probably approach it the way you're thinking about. Log views to a simple table optimized for writes, and periodically update the view count and purge the log table.

With the sort of traffic you're seeing, you may find that such a system will work well if you run your cron more than once an hour.

As Mark says, though, you probably have something else going on that should be figured out.

timdev