Memcached

Memcached
Developer(s)Danga Interactive
Initial releaseMay 22, 2003 (2003-05-22)
Stable release
1.6.32[1] Edit this on Wikidata / 20 October 2024; 49 days ago (20 October 2024)
Repository
Written inC
Operating systemCross-platform
Typedistributed memory caching system
LicenseRevised BSD license[2]
Websitememcached.org Edit this on Wikidata

Memcached (pronounced variously /mɛmkæʃˈdiː/ mem-cash-dee or /ˈmɛmkæʃt/ mem-cashed) is a general-purpose distributed memory-caching system. It is often used to speed up dynamic database-driven websites by caching data and objects in RAM to reduce the number of times an external data source (such as a database or API) must be read. Memcached is free and open-source software, licensed under the Revised BSD license.[2] Memcached runs on Unix-like operating systems (Linux and macOS) and on Microsoft Windows. It depends on the libevent library.

Memcached's APIs provide a very large hash table distributed across multiple machines. When the table is full, subsequent inserts cause older data to be purged in least recently used (LRU) order.[3][4] Applications using Memcached typically layer requests and additions into RAM before falling back on a slower backing store, such as a database.

Memcached has no internal mechanism to track misses which may happen. However, some third party utilities provide this functionality.

Memcached was first developed by Brad Fitzpatrick for his website LiveJournal, on May 22, 2003.[5][6] It was originally written in Perl, then later rewritten in C by Anatoly Vorobey, then employed by LiveJournal.[7] Memcached is now used by many other systems, including YouTube,[8] Reddit,[9] Facebook,[10][11] Pinterest,[12][13] Twitter,[14] Wikipedia,[15] and Method Studios.[16] Google App Engine, Google Cloud Platform, Microsoft Azure, IBM Bluemix and Amazon Web Services also offer a Memcached service through an API.[17][18][19][20]

Software architecture

The system uses a client–server architecture. The servers maintain a key–value associative array; the clients populate this array and query it by key. Keys are up to 250 bytes long and values can be at most 1 megabyte in size.

Clients use client-side libraries to contact the servers which, by default, expose their service at port 11211. Both TCP and UDP are supported. Each client knows all servers; the servers do not communicate with each other. If a client wishes to set or read the value corresponding to a certain key, the client's library first computes a hash of the key to determine which server to use. This gives a simple form of sharding and scalable shared-nothing architecture across the servers. The server computes a second hash of the key to determine where to store or read the corresponding value. The servers keep the values in RAM; if a server runs out of RAM, it discards the oldest values. Therefore, clients must treat Memcached as a transitory cache; they cannot assume that data stored in Memcached is still there when they need it. Other databases, such as MemcacheDB, Couchbase Server, provide persistent storage while maintaining Memcached protocol compatibility.

If all client libraries use the same hashing algorithm to determine servers, then clients can read each other's cached data.

A typical deployment has several servers and many clients. However, it is possible to use Memcached on a single computer, acting simultaneously as client and server. The size of its hash table is often very large. It is limited to available memory across all the servers in the cluster of servers in a data center. Where high-volume, wide-audience Web publishing requires it, this may stretch to many gigabytes. Memcached can be equally valuable for situations where either the number of requests for content is high, or the cost of generating a particular piece of content is high.

Security

Most deployments of Memcached are within trusted networks where clients may freely connect to any server. However, sometimes Memcached is deployed in untrusted networks or where administrators want to exercise control over the clients that are connecting. For this purpose Memcached can be compiled with optional SASL authentication support. The SASL support requires the binary protocol.

A presentation at BlackHat USA 2010 revealed that a number of large public websites had left Memcached open to inspection, analysis, retrieval, and modification of data.[21]

Even within a trusted organisation, the flat trust model of memcached may have security implications. For efficient simplicity, all Memcached operations are treated equally. Clients with a valid need for access to low-security entries within the cache gain access to all entries within the cache, even when these are higher-security and that client has no justifiable need for them. If the cache key can be either predicted, guessed or found by exhaustive searching, its cache entry may be retrieved.

Some attempt to isolate setting and reading data may be made in situations such as high volume web publishing. A farm of outward-facing content servers have read access to memcached containing published pages or page components, but no write access. Where new content is published (and is not yet in memcached), a request is instead sent to content generation servers that are not publicly accessible to create the content unit and add it to memcached. The content server then retries to retrieve it and serve it outwards.

Used as a DDoS attack vector

In February 2018, CloudFlare reported that misconfigured memcached servers were used to launch DDoS attacks in large scale.[22] The memcached protocol over UDP has a huge amplification factor, of more than 51000.[23] Victims of the DDoS attacks include GitHub, which was flooded with 1.35 Tbit/s peak incoming traffic.[24]

This issue was mitigated in Memcached version 1.5.6, which disabled UDP protocol by default.[25]

Example code

Note that all functions described on this page are pseudocode only. Memcached calls and programming languages may vary based on the API used.

Converting database or object creation queries to use Memcached is simple. Typically, when using straight database queries, example code would be as follows:

 function get_foo(int userid)
     data = db_select("SELECT * FROM users WHERE userid = ?", userid)
     return data

After conversion to Memcached, the same call might look like the following

 function get_foo(int userid)
     /* first try the cache */
     data = memcached_fetch("userrow:" + userid)
     if not data
         /* not found : request database */
         data = db_select("SELECT * FROM users WHERE userid = ?", userid)
         /* then store in cache until next get */
         memcached_add("userrow:" + userid, data)
     end

     return data

The client would first check whether a Memcached value with the unique key "userrow:userid" exists, where userid is some number. If the result does not exist, it would select from the database as usual, and set the unique key using the Memcached API add function call.

However, if only this API call were modified, the server would end up fetching incorrect data following any database update actions: the Memcached "view" of the data would become out of date. Therefore, in addition to creating an "add" call, an update call would also be needed using the Memcached set function.

 function update_foo(int userid, string dbUpdateString)
     /* first update database */
     result = db_execute(dbUpdateString)
     if result
         /* database update successful : fetch data to be stored in cache */
         data = db_select("SELECT * FROM users WHERE userid = ?", userid)
         /* the previous line could also look like data = createDataFromDBString(dbUpdateString) */
         /* then store in cache until next get */
         memcached_set("userrow:" + userid, data)

This call would update the currently cached data to match the new data in the database, assuming the database query succeeds. An alternative approach would be to invalidate the cache with the Memcached delete function, so that subsequent fetches result in a cache miss. Similar action would need to be taken when database records were deleted, to maintain either a correct or incomplete cache.

An alternate cache-invalidation strategy is to store a random number in an agreed-upon cache entry and to incorporate this number into all keys that are used to store a particular kind of entry. To invalidate all such entries at once, change the random number. Existing entries (which were stored using the old number) will no longer be referenced and so will eventually expire or be recycled.

  function store_xyz_entry(int key, string value)
      /* Retrieve the random number - use zero if none exists yet.
      *  The key-name used here is arbitrary. */ 
      seed = memcached_fetch(":xyz_seed:")
      if not seed
          seed = 0
      /* Build the key used to store the entry and store it.
      *  The key-name used here is also arbitrary. Notice that the "seed" and the user's "key"
      *  are stored as separate parts of the constructed hashKey string: ":xyz_data:(seed):(key)." 
      *  This is not mandatory, but is recommended. */
      string hashKey = sprintf(":xyz_data:%d:%d", seed, key)
      memcached_set(hashKey, value)

  /* "fetch_entry," not shown, follows identical logic to the above. */

  function invalidate_xyz_cache()
      existing_seed = memcached_fetch(":xyz_seed:")
      /* Coin a different random seed */
      do
          seed = rand()
      until seed != existing_seed
      /* Now store it in the agreed-upon place. All future requests will use this number. 
      *  Therefore, all existing entries become un-referenced and will eventually expire. */
      memcached_set(":xyz_seed:", seed)

Usage

See also

References

  1. ^ "Release 1.6.32". 20 October 2024. Retrieved 22 October 2024.
  2. ^ a b "Memcached license". GitHub. Retrieved 2014-06-27.
  3. ^ "Google Code Archive - Long-term storage for Google Code Project Hosting". Code.google.com. Retrieved 2017-06-25.
  4. ^ "Google Code Archive - Long-term storage for Google Code Project Hosting". Code.google.com. Retrieved 2017-06-25.
  5. ^ [1]. Community.livejournal.com (2003-05-22). Retrieved on 2013-09-18.
  6. ^ [2]. Community.livejournal.com (2003-05-27). Retrieved on 2013-09-18.
  7. ^ "lj_dev: memcached". 2013-02-25. Archived from the original on 2013-02-25. Retrieved 2017-06-25.
  8. ^ Cuong Do Cuong (Engineering manager at YouTube/Google) (June 23, 2007). Seattle Conference on Scalability: YouTube Scalability (Online Video - 26th minute). Seattle: Google Tech Talks.
  9. ^ Whitaker, Keir (2010-05-17). "Steve Huffman on Lessons Learned at Reddit | Carsonified". Archived from the original on 2010-05-17. Retrieved 2017-06-25.
  10. ^ "Scaling memcached at Facebook". Facebook.com. 2008-12-12. Retrieved 2017-06-25.
  11. ^ Scaling Memcache at Facebook. USENIX. 2002. ISBN 9781931971003. Retrieved 2017-06-25.
  12. ^ "Building Pinterest in the cloud". Pinterest Careers. 2013-06-19. Retrieved 2018-03-09.
  13. ^ "A comprehensive, fast, pure-Python memcached client". Github.com. 2018-01-08. Retrieved 2018-03-09.
  14. ^ "It's Not Rocket Science, But It's Our Work". Blog.twitter.com. 2008-06-01. Retrieved 2017-06-25.
  15. ^ "memcached". MediaWiki. Retrieved 2017-06-25.
  16. ^ Rez BoF, SIGGRAPH 2019, archived from the original on 2021-12-12, retrieved 2019-08-09
  17. ^ "Memcache Examples | App Engine standard environment for Python | Google Cloud Platform". Code.google.com. 2017-03-22. Retrieved 2017-06-25.
  18. ^ "About In-Role Cache for Azure Cache". Msdn.microsoft.com. 2015-08-25. Retrieved 2017-06-25.
  19. ^ Verge, Jason (2014-09-23). "Redis Labs: We Have 3,000 Paying Cloud In-Memory NoSQL Customers". Data Center Knowledge. Retrieved 2016-09-10.
  20. ^ "AWS | Amazon ElastiCache – in-memory data store and cache". Aws.amazon.com. Retrieved 2017-06-25.
  21. ^ "SensePost | Blackhat write-up: Go-derper and mining memcaches". Archived from the original on 2018-12-21. Retrieved 2016-09-02.
  22. ^ "Memcrashed - Major amplification attacks from UDP port 11211". CloudFlare. 27 Feb 2018. Retrieved 3 March 2018.
  23. ^ Jeffrey, Cal (Mar 1, 2018). "GitHub falls victim to largest DDoS attack ever recorded".
  24. ^ "February 28th DDoS Incident Report". March 1, 2018. Retrieved 3 March 2018.
  25. ^ "Memcached 1.5.6 Release Notes". GitHub. 2018-02-27. Retrieved 3 March 2018.
  26. ^ "Speedy MySQL 5.6 takes aim at NoSQL, MariaDB". Theregister.co.uk. Retrieved 2017-06-25.
  27. ^ David Felcey (2014-08-13). "Getting Started With The Coherence Memcached Adaptor | Oracle Coherence Blog". Blogs.oracle.com. Archived from the original on 2017-02-23. Retrieved 2017-06-25.
  28. ^ "Using the Memcached protocol endpoint with Infinispan". infinispan.org. Retrieved 2022-04-19.

Read other articles:

روجر فاديم (بالفرنسية: Roger Vadim)‏  معلومات شخصية اسم الولادة (بالروسية: Вадим Игоревич Племянников)‏  الميلاد 26 يناير 1928(1928-01-26)باريس الوفاة 11 فبراير 2000 (72 سنة)باريس سبب الوفاة لمفوما  مواطنة فرنسا  الزوجة بريجيت باردو (20 ديسمبر 1952–6 ديسمبر 1957)جين فوندا (14 أغسطس 1965–16 ...

 

この項目では、1861年から1946年まで存在した、現在のイタリア共和国の全土を領域とした王国について説明しています。 中世に存在したイタリア王権については「イタリア王国 (神聖ローマ帝国)」をご覧ください。 ナポレオン1世を王として建国されたフランスの衛星国については「イタリア王国 (1805年-1814年)」をご覧ください。 この記事は検証可能な参考文献や出典が

 

دابيتان (بالإنجليزية: City of Dapitan)‏     خريطة الموقع تاريخ التأسيس 1629  تقسيم إداري البلد الفلبين  [1] التقسيم الأعلى زامبوانجا ديل نورت  خصائص جغرافية إحداثيات 8°39′18″N 123°25′27″E / 8.6549°N 123.4243°E / 8.6549; 123.4243  المساحة 390٫53 كيلومتر مربع الارتفاع 33 متر&...

Dieser Artikel behandelt die Schauspielerin. Zu dem nach ihr benannten Trimaran siehe Brigitte Bardot (Schiff), zum Lied siehe Brigitte Bardot (Lied). Brigitte Bardot, 1961 Brigitte Anne-Marie Bardot, kurz Brigitte Bardot [briˌʒit bɑrˈdo] (* 28. September 1934 in Paris), oft abgekürzt als BB, ist eine französische Filmschauspielerin und Sängerin sowie Model und Sexsymbol. Nach ihrer Filmkarriere in den 1950er und 1960er Jahren wurde sie auch bekannt als Tierschutzaktivistin und promine...

 

Venues for indoor prostitution in Paris, France France Prostitution articles AreasProstitution in FranceProstitution in ParisProstitution in Overseas France BrothelsBrothels in ParisAux Belles PoulesLe ChabanaisLa Fleur blancheL'Étoile de KléberLanterne VerteLe FourcyMaison SouquetOne-Two-TwoLe Sphinx LawLoi Marthe Richard OrganisationsLes amis du bus des femmes Red-light districtsBois de BoulogneQuartier Pigalle OtherBordel militaire de campagne; Brigade de répression du proxénétisme; T...

 

Kuil IV Tikal Kuil IV Tikal adalah sebuah piramida Maya kuno yang terletak di reruntuhan kota Tikal di Guatemala modern. Kuil ini merupakan salah satu bangunan tertinggi dan terbesar di peradaban Maya.[1] Piramida ini dibangun sekitar tahun 741 M.[1] Kuil IV terletak di sisi barat pusat kota Tikal.[1] Piramida ini dibangun untuk merayakan masa kekuasaan raja Tikal yang ke-27, Yik'in Chan K'awiil, walaupun mungkin piramida ini dibangun setelah kematiannya untuk dijadika...

You can help expand this article with text translated from the corresponding article in German. (September 2022) Click [show] for important translation instructions. View a machine-translated version of the German article. Machine translation, like DeepL or Google Translate, is a useful starting point for translations, but translators must revise errors as necessary and confirm that the translation is accurate, rather than simply copy-pasting machine-translated text into the English Wiki...

 

Wali Kota CilegonPetahanaHelldy Agustiansejak 26 Februari 2021Masa jabatan5 tahun dan dapat dipilih kembali untuk satu kali masa jabatanDibentuk29 Juli 1987; 36 tahun lalu (1987-07-29)Pejabat pertamaNurman SuriadintaSitus webSitus web resmi Berikut adalah daftar Wali Kota Cilegon secara definitif sejak tahun 1999 di bawah Pemerintah Republik Indonesia. Nomor urut Wali Kota Potret Partai Awal Akhir Masa jabatan Periode Wakil Ref. 1   Aat Syafaat(tidak diketahui–2016) Golkar 7 ...

 

Town in Chūbu, JapanMinamiechizen 南越前町TownMinamiechizen Town Hall FlagSealLocation of Minamiechizen in Fukui PrefectureMinamiechizen Coordinates: 35°50′6.3″N 136°11′40″E / 35.835083°N 136.19444°E / 35.835083; 136.19444CountryJapanRegionChūbu (Hokuriku)PrefectureFukuiDistrictNanjōArea • Total343.69 km2 (132.70 sq mi)Population (July 2018) • Total10,745 • Density31/km2 (81/sq mi)Time...

1997 single by Marcy Playground Sex and CandySingle by Marcy Playgroundfrom the album Marcy Playground and Hurricane Streets: Original Motion Picture Soundtrack B-side The Angel of Forever Sleep Memphis ReleasedSeptember 15, 1997 (1997-09-15)GenrePost-grungeLength2:52LabelCapitolSongwriter(s)John WozniakProducer(s) John Wozniak Jim Sabella Jared Kotler Kenny Gioia Marcy Playground singles chronology Saint Joe on the School Bus (1997) Sex and Candy (1997) Sherry Fraser (1998) Mu...

 

American murder victim (1985–2006) Dana DoddDodd in 2003BornDana Lynn DoddSeptember 6, 1985[1]Disappearedc. 2003StatusIdentified after 12 yearsDiedOctober 28, 2006 (aged 21)Body discoveredOctober 29, 2006 Kilgore, Texas, USResting placeWhite Cemetery, Longview, Texas, USKnown forFormerly unidentified victim of homicide Dana Lynn Dodd was a formerly unidentified American murder victim whose body was found in 2006 in Kilgore, Texas. In 2013, investigators had hoped that a n...

 

This article is about the film. For the battle its based on, see Siege of Sevastopol (1941–1942). 2015 filmBattle for SevastopolRussian theatrical release posterDirected bySergey MokritskiyWritten byMaksim BudarinMaksim DankevichLeonid KorinEgor OlesovProduced byNatalia MokritskayaEgor OlesovStarringYulia PeresildJoan BlackhamYevgeny TsyganovOleg VasilkovVitaliy LinetskiyCinematographyYury Korol'Music byEvgeniy GalperinDistributed by20th Century FoxRelease date April 2, 2015 ...

Unincorporated area in Florida, U.S. Elwood Park is an unincorporated area in Manatee County, Florida, United States. History Elwood Park is a neighborhood located at what was a 1500-acre farming community near Oneco on the Braden River. The area was named for J. Elwood Moore, a Sarasota banker and developer of the area who established the New Home Development Company in the mid-1910s. The New Home Development Company advertised the agricultural tracts in the Midwest to Northerners willing to...

 

Ich will dich lieben, meine StärkeChristian hymnsThe hymnwriter in 1668EnglishI want to love you, my strengthTextby Angelus SilesiusLanguageGermanMelody by Georg Joseph by Johann Balthasar König Published1657 (1657) Ich will dich lieben, meine Stärke (I want to love you, my strength) is a sacred poem by Johann Scheffler who is known by his pen name Angelus Silesius. It appeared first in a poem collection, Heilige Seelen-Lust (Holy bliss of the soul) in 1657, and has become a Christian...

 

Voce principale: Associazione Calcio Femminile Aurora Bergamo. U.S. Aurora Mombretto 1972Stagione 1982Sport calcio Squadra Aurora Mombretto Allenatore Vincenzo Ponzo Presidente Serie A13º posto, retrocessa in Serie B. Coppa Italia???. 1981 1983 Si invita a seguire il modello di voce Questa voce raccoglie le informazioni riguardanti la società calcistica femminile Unione Sportiva Aurora Mombretto 1972 nelle competizioni ufficiali della stagione 1982. Indice 1 Stagione 2 Rosa 3 Note 4 Bi...

Questa voce sull'argomento calciatori venezuelani è solo un abbozzo. Contribuisci a migliorarla secondo le convenzioni di Wikipedia. Segui i suggerimenti del progetto di riferimento. Alejandro Moreno Nazionalità  Venezuela Altezza 175 cm Peso 77 kg Calcio Ruolo Attaccante Termine carriera 2012 Carriera Squadre di club1 2003-2004 L.A. Galaxy70 (12)2004-2005 S.J. Earthquakes33 (8)2006-2007 Houston Dynamo38 (3)2007-2009 Columbus Crew77 (21)2010 Philadelphia U...

 

Bescherming voor Teddy Bear Oorspronkelijke titel Protection pour Teddy Bear Auteur(s) Gérard de Villiers Vertaler Else van Dijk-Foppema Land Frankrijk Taal Nederlands Reeks/serie S.A.S. Genre thriller Uitgever A.W. Bruna Uitgevers Uitgegeven 1978 Medium Pocket Pagina's 188 Grootte engewicht 18 cm ISBN 9022917894 Voorloper De schatten van de keizer Vervolg Een onmogelijke opdracht in Somalië Portaal    Literatuur De ligging van het Verenigd Koninkrijk in Europa. Een overzichtskaar...

 

British Army general and politician (1912–1987) Sir James d'Avigdor-GoldsmidBt, CB, OBE, MCMember of Parliament for Lichfield and TamworthIn office18 June 1970 – 20 September 1974Preceded byJulian SnowSucceeded byBruce Grocott Personal detailsBorn(1912-12-19)19 December 1912Died6 September 1987(1987-09-06) (aged 74)Political partyConservativeRelativesSee Goldsmid familyAlma materRoyal Military College, SandhurstAwardsCompanion of the Order of the Bath...

قرية راود  - قرية -  تقسيم إداري البلد  اليمن المحافظة محافظة المحويت المديرية مديرية حفاش العزلة عزلة الملاحنة السكان التعداد السكاني 2004 السكان 773   • الذكور 382   • الإناث 391   • عدد الأسر 109   • عدد المساكن 96 معلومات أخرى التوقيت توقيت اليمن (+3 غرينيتش)...

 

Indian statesman Rajah, SirTanjore Madhava RaoKCSIPortrait of Sir T. Madhava RaoDiwan of BarodaIn office10 May 1875 – 28 September 1882MonarchMaharaja Sayajirao Gaekwad IIIPreceded byDadabhai NaorojiSucceeded byKazi ShahabuddinDiwan of IndoreIn office1873–1875MonarchTukojirao Holkar IIPreceded byTukojirao Holkar IISucceeded byR. Raghunatha RaoDiwan of TravancoreIn office1857 – May 1872MonarchsUthram Thirunal, Ayilyam ThirunalPreceded byKrishna RaoSucceeded byA. Seshayy...

 

Strategi Solo vs Squad di Free Fire: Cara Menang Mudah!