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

PHPMaster.com: Generators in PHP

DevShed: Authentication Scripts for a User Management Application

PHPBuilder.com: Creating an Online Survey - Part 2

Alex Mills' Blog: Why WordPress Doesn't Have Built-In Persistent Caching

Nikita Popov: Cooperative multitasking using coroutines (in PHP!)


Community Events





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


series community list deployment api package update interview podcast introduction library zendserver release language install laravel symfony tips framework opinion

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