I have a query like
update pageviews set count = count + 1 where pageid = $pageid
This statement is executed each time a webpage is viewed. Therefore, the column count is incremented each time the page is viewed.
My table is of InnoDB type.
Assuming thousands of pageviews can happen per second, is this not scalable? Can i run into concurrency issues? Like query locking etc?
Someone told me that i should be using queues for purposes like this. Why do i need to use a queue? In what sort of condition could my data be corrupted or scalability could become a concern?
Out of the box, on commodity hardware, InnoDB handles about 100 such statements per second. There are no concurrency or locking problems, just performance problems.
innodb_flush_log_at_trx_commit
defaults to 1 for security. But that requires a disk I/O to a log for every transaction. 2 is much faster, and a reasonable compromise. (A crash may lose one second's worth of transactions.)Your
UPDATE
is probablyautocommited
? Or in a transaction by itself? Can it be batched in any way? If so, that would cut back on the overhead.A pageview is handled by a web server, correct? Can it collect some pageids before actually writing to the table? Even if it collected for one second, that could be a significant speedup. If you do this, be sure to sort the
IN
list inupdate pageviews set count = count + 1 where pageid IN (...)
. That will cut back on the likelihood of deadlocks.Handle errors from your
UPDATE
. (Otherwise, your data will be 'wrong' or 'corrupted'.)