News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Przemek Sobstel:
Preventing the Dogpile Effect
August 11, 2014 @ 11:47:28

Przemek Sobstel has a recent post investigating an interesting theory in caching of any kind of application, not just PHP ones. He looks at the dogpile effect: when a cache expires and the database or host cannot catch up with so many non-cached requests coming in.

Implementing caching in web apps seems to be simple. You check if value is cached. If it is, you fetch cached value from cache and serve it. If it's not, you generate new value and store in cache for future requests. Simple like that. However, what if value expires and then you get hundreds of requests? It cannot be served from cache anymore, so your databases are hit with numerous processes trying to re-generate the value. And the more requests databases receive, the slower and less responsive they get. Load spikes. Until eventually they likely go down.

He recommends using something called a "semaphore lock" to help prevent this kind of issue from happening. This lock prevents the removal of any stale content until after one process has finished refreshing the requested data. Only once the lock is released are the other processes allows to serve the fresh data. He includes some PHP pseudo-code that illustrates the point: trying to fetch the content, checking for the lock and releasing it when the single process is done with the refresh. He includes a link to a full implementation as well. He's also written up a full library, Metaphore, that integrates this into a full caching system.

0 comments voice your opinion now!
dogpile effect theory cache tutorial metaphore semaphore

Link: http://www.sobstel.org/blog/preventing-dogpile-effect/

blog comments powered by Disqus

Similar Posts

Twilio Blog: How to Build an MMS Ticketing System Using PHP, Laravel and Twilio

Developer.com: Amazon Web Services and the Zend Framework

PHPro.org: SPL AppendIterator

FuzzyOpinions Blog: Tutorial: improving security with a PHP Captcha

NetTuts.com: Understanding and Working with Relationships Between Data in WordPress


Community Events

Don't see your event here?
Let us know!


api interview laravel5 framework development opinion extension introduction library community psr7 voicesoftheelephpant unittest podcast series language release laravel conference video

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework