rss
4

Quick Tip #3 – Article View Counter for WordPress

  • Sumo

I have examined several WordPress plugins for counting number of article views and I was shocked! All of them are using  update_post_meta() function which is the worst case scenario for article counting. Why?

Because update_post_meta() function stores information in postmeta table. The type of this table by default is MyISAM. Which means that every time a person is viewing an article, update_post_meta() function updates the postmeta table by locking it with TABLE_LOCK. Meaning that during update process all other processes (such as getting article view count from database) are put to a WAITING pool.

For small websites this is more than OK! But for large ones, with high traffic, it is a disaster and significant performance degradation. Imagine a website with 500 hits per second.

Based on your server configuration, starting from some point visitors should wait for server response because for viewing article WordPress calls get_post_meta() function for meta information, but on the same time update_post_meta() function LOCKS entire postmeta table for updating article view count!

Quick Tip #3 – Article View Counter for WordPress

Do not use update_post_meta() function for counting number of article views OR change postmeta table type to InnoDB.

_____
Read all quick tips. Stay tuned! And come back for another quick tip! You can subscribe to new posts by RSS feed or email subscription.

About the Author

Edgar Marukyan is an expert of website development and performance optimization, who maintains and consults clients with high load traffic websites.. If you need an assistance, feel free to drop me a line.         Website - Twitter - Facebook

Comments (4)

Trackback URL | Comments RSS Feed

  1. Randy says:

    Do you have a plugin with your code in it or is it possible?

  2. bevislarsen says:

    Here define several functions of article view counter in wordpress based on your server configuration.

Leave a Reply




If you want a picture to show with your comment, go get a Gravatar.