{"id":707,"date":"2008-01-28T20:22:18","date_gmt":"2008-01-29T01:22:18","guid":{"rendered":"http:\/\/www.bytebot.net\/blog\/archives\/2008\/01\/28\/memcache-keeping-data-in-the-handiest-place-memory"},"modified":"2008-07-22T19:13:01","modified_gmt":"2008-07-23T00:13:01","slug":"memcache-keeping-data-in-the-handiest-place-memory","status":"publish","type":"post","link":"http:\/\/www.bytebot.net\/blog\/archives\/2008\/01\/28\/memcache-keeping-data-in-the-handiest-place-memory","title":{"rendered":"Memcache, keeping data in the handiest place: memory"},"content":{"rendered":"<p>While I ducked out of Giuseppe&#8217;s miniconf talk, on MySQL Proxy (a great session, might I add &#8211; it takes up 2 slots right up until lunch), I went over to the LinuxChix miniconf, to attend a talk about <a href=\"http:\/\/conf.au.linuxchix.org\/schedule\/memcache-brendawallace\/\">memcache<\/a>, by Brenda Wallace. Brenda, works at <a href=\"http:\/\/www.catalyst.net.nz\/\">Catalyst IT<\/a>, in New Zealand &#8211; they use a lot of memcache, in the telco business.<\/p>\n<p>Memcache: volatile cache for keeping data in. Its a daemon. The code, can connect to memcache, put values in, read values, delete values. An example of how to use memcache, is given in PHP5.<\/p>\n<p>A killer feature, is the setting of expiry. You can tell it to cache for 30 seconds, and then forget about it, no worries there.<\/p>\n<p>What do you store? Database, generated content (front page of a website, just like a blog even), web service lookups (useful in telco, or say, if you&#8217;re playing with the Flickr API), LDAP, things that are far away (from the other side of the pond, etc.).<\/p>\n<p>Wikipedia made memcache famous, Twitter uses it a lot, and there are probably heaps more.<\/p>\n<p>Many APIs, and there&#8217;s a postgres client too. There&#8217;s a memcache storage engine for MySQL as well.<\/p>\n<p>Code should be written such that if its in memcache, use that, otherwise, get it from the database and put it in memcache.<\/p>\n<p>Another nifty feature, is incrementing a value &#8211; increment functions $memc-&gt;inc(&#8216;name&#8217;);. You can also read stats, to see a cache hit or miss.<\/p>\n<p>Memcache doesn&#8217;t have locks. Memcache is not atomic. There are other libraries out there to do locking, there is a known Perl library for this.<\/p>\n<p>What not to store? Remember, its completely volatile. Don&#8217;t store anything you&#8217;d be sad to lose, and make sure the real copy is safe elsewhere. There is no method to get list of keys in store. There is a 1MB limit per item, so if data is larger than that, you&#8217;re in trouble.<\/p>\n<p>Where do you run it? Remember, it is memory hungry, but CPU lite. Running memcache on the webserver is the recommended method, so beware of the security.<\/p>\n<p>There is no authentication. You just connect (no username, no password). So, when running on the web server, you probably want a firewall. In shared hosting, everyone on that host can read\/write to your memcache instance.<\/p>\n<p>No check for validity. No referential integrity, its not a database.<\/p>\n<p>There is transparent failover! So if one fails, the client just automatically connects it to another.<\/p>\n<p>Usage ideas? Communicate between layers (talk to a PHP app, from Java). Instead of squid, you can store stuff in memcache, if you want.<\/p>\n<p>Some competing technologies: Tugela &#8211; same concept, but its saved to disk, so it will survive a reboot. This is the Wikipedia fork, of memcached. Couch DB is mention, but its not really a competitor, seeing that its a document database. Lucene is another competitor, but remember, its a fast indexer, and its non-volatile.<\/p>\n<p><em>I haven&#8217;t looked into memcached much, but its quite clear, its a great technology to look at. Now the fact that you can use the MySQL storage engine, it might actually be really, interesting.<\/em><\/p>\n<p>Technorati Tags: <a class=\"performancingtags\" rel=\"tag\" href=\"http:\/\/technorati.com\/tag\/linux.conf.au\">linux.conf.au<\/a>, <a class=\"performancingtags\" rel=\"tag\" href=\"http:\/\/technorati.com\/tag\/lca08\">lca08<\/a>, <a class=\"performancingtags\" rel=\"tag\" href=\"http:\/\/technorati.com\/tag\/linuxchix\">linuxchix<\/a>, <a class=\"performancingtags\" rel=\"tag\" href=\"http:\/\/technorati.com\/tag\/memcached\">memcached<\/a><\/p>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-email\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-email sd-button share-icon\" href=\"mailto:?subject=%5BShared%20Post%5D%20Memcache%2C%20keeping%20data%20in%20the%20handiest%20place%3A%20memory&body=http%3A%2F%2Fwww.bytebot.net%2Fblog%2Farchives%2F2008%2F01%2F28%2Fmemcache-keeping-data-in-the-handiest-place-memory&share=email\" target=\"_blank\" title=\"Click to email a link to a friend\" data-email-share-error-title=\"Do you have email set up?\" data-email-share-error-text=\"If you&#039;re having problems sharing via email, you might not have email set up for your browser. You may need to create a new email yourself.\" data-email-share-nonce=\"650ea18063\" data-email-share-track-url=\"http:\/\/www.bytebot.net\/blog\/archives\/2008\/01\/28\/memcache-keeping-data-in-the-handiest-place-memory?share=email\"><span>Email<\/span><\/a><\/li><li class=\"share-facebook\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-facebook-707\" class=\"share-facebook sd-button share-icon\" href=\"http:\/\/www.bytebot.net\/blog\/archives\/2008\/01\/28\/memcache-keeping-data-in-the-handiest-place-memory?share=facebook\" target=\"_blank\" title=\"Click to share on Facebook\" ><span>Facebook<\/span><\/a><\/li><li class=\"share-linkedin\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-linkedin-707\" class=\"share-linkedin sd-button share-icon\" href=\"http:\/\/www.bytebot.net\/blog\/archives\/2008\/01\/28\/memcache-keeping-data-in-the-handiest-place-memory?share=linkedin\" target=\"_blank\" title=\"Click to share on LinkedIn\" ><span>LinkedIn<\/span><\/a><\/li><li class=\"share-twitter\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-twitter-707\" class=\"share-twitter sd-button share-icon\" href=\"http:\/\/www.bytebot.net\/blog\/archives\/2008\/01\/28\/memcache-keeping-data-in-the-handiest-place-memory?share=twitter\" target=\"_blank\" title=\"Click to share on Twitter\" ><span>Twitter<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>While I ducked out of Giuseppe&#8217;s miniconf talk, on MySQL Proxy (a great session, might I add &#8211; it takes up 2 slots right up until lunch), I went over to the LinuxChix miniconf, to attend a talk about memcache, by Brenda Wallace. Brenda, works at Catalyst IT, in New Zealand &#8211; they use a [&hellip;]<\/p>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-email\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-email sd-button share-icon\" href=\"mailto:?subject=%5BShared%20Post%5D%20Memcache%2C%20keeping%20data%20in%20the%20handiest%20place%3A%20memory&body=http%3A%2F%2Fwww.bytebot.net%2Fblog%2Farchives%2F2008%2F01%2F28%2Fmemcache-keeping-data-in-the-handiest-place-memory&share=email\" target=\"_blank\" title=\"Click to email a link to a friend\" data-email-share-error-title=\"Do you have email set up?\" data-email-share-error-text=\"If you&#039;re having problems sharing via email, you might not have email set up for your browser. You may need to create a new email yourself.\" data-email-share-nonce=\"650ea18063\" data-email-share-track-url=\"http:\/\/www.bytebot.net\/blog\/archives\/2008\/01\/28\/memcache-keeping-data-in-the-handiest-place-memory?share=email\"><span>Email<\/span><\/a><\/li><li class=\"share-facebook\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-facebook-707\" class=\"share-facebook sd-button share-icon\" href=\"http:\/\/www.bytebot.net\/blog\/archives\/2008\/01\/28\/memcache-keeping-data-in-the-handiest-place-memory?share=facebook\" target=\"_blank\" title=\"Click to share on Facebook\" ><span>Facebook<\/span><\/a><\/li><li class=\"share-linkedin\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-linkedin-707\" class=\"share-linkedin sd-button share-icon\" href=\"http:\/\/www.bytebot.net\/blog\/archives\/2008\/01\/28\/memcache-keeping-data-in-the-handiest-place-memory?share=linkedin\" target=\"_blank\" title=\"Click to share on LinkedIn\" ><span>LinkedIn<\/span><\/a><\/li><li class=\"share-twitter\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-twitter-707\" class=\"share-twitter sd-button share-icon\" href=\"http:\/\/www.bytebot.net\/blog\/archives\/2008\/01\/28\/memcache-keeping-data-in-the-handiest-place-memory?share=twitter\" target=\"_blank\" title=\"Click to share on Twitter\" ><span>Twitter<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_options":[]},"categories":[1],"tags":[335],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4vJD-bp","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":847,"url":"http:\/\/www.bytebot.net\/blog\/archives\/2008\/06\/25\/how-facebook-serves-pictures","url_meta":{"origin":707,"position":0},"title":"How Facebook serves pictures","date":"25\/6\/2008","format":false,"excerpt":"I caught Facebook - Needle in a Haystack: Efficient Storage of Billions of Photos on Flowgram. First up, I'm not a big fan of Flowgrams - the format is sensible, slide and voice, is excellent, but the delivery in a web browser isn't optimal... make downloadable videos! The talk however,\u2026","rel":"","context":"In &quot;MySQL&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":716,"url":"http:\/\/www.bytebot.net\/blog\/archives\/2008\/02\/14\/mysql-miniconf-videos-from-linuxconfau-2008","url_meta":{"origin":707,"position":1},"title":"MySQL Miniconf videos, from linux.conf.au 2008","date":"14\/2\/2008","format":false,"excerpt":"If you couldn't make the MySQL MiniConf at linux.conf.au 2008, no worries - there's recorded video!Upcoming MySQL Features (Stewart Smith) - focused on the future, as opposed to what's available right now\/soonMySQL Indexing Methods (Jonathon Coombes) AND MySQL Optimisation by Design (Arjen Lentz)- the slides are viewable from the video,\u2026","rel":"","context":"In &quot;MySQL&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":528,"url":"http:\/\/www.bytebot.net\/blog\/archives\/2007\/04\/23\/scaling-twitter-is-twitter-is-udp-or-tcp-its-definitely-udp","url_meta":{"origin":707,"position":2},"title":"Scaling Twitter: &#8220;Is Twitter is UDP or TCP? Its definitely UDP.&#8221;","date":"23\/4\/2007","format":false,"excerpt":"Presented by Blaine Cook, a developer from Odeo, now probably CTO of Twitter (Obvious Corp spawed, I think). There's a video and slides (yes, you need evil Flash so I haven't viewed it myself). Then there are my notes... possibly with some thoughts attached to them. No, they're not organized,\u2026","rel":"","context":"In &quot;MySQL&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":536,"url":"http:\/\/www.bytebot.net\/blog\/archives\/2007\/04\/26\/extreme-makeover-database-or-mysqlyoutube","url_meta":{"origin":707,"position":3},"title":"Extreme Makeover: Database or MySQL@YouTube","date":"26\/4\/2007","format":false,"excerpt":"Arguably one of the most interesting keynotes (and technical to boot!), Paul Tuckfield not only entertained us in his 40 minute keynote, he also did so outside when the keynotes ended. Just the DBA at PayPal, just the DBA at YouTube. Only 3 DBAs at YouTube that make it all\u2026","rel":"","context":"In &quot;MySQL&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1432,"url":"http:\/\/www.bytebot.net\/blog\/archives\/2009\/04\/17\/frank-mashraqi-on-hadoop-memcached-and-why-the-mysql-conference-is-cool","url_meta":{"origin":707,"position":4},"title":"Frank Mashraqi on Hadoop, memcached, and why the MySQL Conference is cool","date":"17\/4\/2009","format":false,"excerpt":"Today I spoke with Farhan \"Frank\" Mashraqi, former Fotolog DBA, now working at a startup, NetEdge, working on social analytics. He's talking about the two sessions he's giving next week at the MySQL Conference & Expo 2009, as well as the benefits of being at the MySQL Conference & Expo.\u2026","rel":"","context":"In &quot;MySQL&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1018,"url":"http:\/\/www.bytebot.net\/blog\/archives\/2008\/09\/11\/project-kenai","url_meta":{"origin":707,"position":5},"title":"Project Kenai","date":"11\/9\/2008","format":false,"excerpt":"Sun is a huge company. So it comes as no surprise that I'm finding out about Project Kenai via Tim Bray, instead of some internal mailing list (believe me, there must be thousands). Tim's got a Q&A with Nick Sieger, who's one of the chieftains behind Kenai. I find it\u2026","rel":"","context":"In &quot;General&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"amp_enabled":true,"_links":{"self":[{"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/posts\/707"}],"collection":[{"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/comments?post=707"}],"version-history":[{"count":1,"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/posts\/707\/revisions"}],"predecessor-version":[{"id":872,"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/posts\/707\/revisions\/872"}],"wp:attachment":[{"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/media?parent=707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/categories?post=707"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/tags?post=707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}