Memcached

from Wikipedia, the free encyclopedia
Memcached
Basic data

developer Danga Interactive
Current  version 1.6.6
( May 13, 2020 )
operating system Unix derivatives , Windows
programming language C.
category Cache server
License BSD license
German speaking No
memcached.org

Memcached [ mɛm.kæʃ.tː ] is under the BSD license published cache - Server for general Depositing and retrieval of data from memory. The software is mainly used for websites that temporarily store data from database systems on the server. It is used to improve the performance of many dynamic websites with a database connection by keeping important data in the main memory to avoid hard disk access or to minimize the need to call up complex and frequently used database queries - especially SELECT statements.

history

Memcached was originally developed by Danga Interactive for the LiveJournal Internet portal . The software was under the GPL until June 15, 2003 , when the licensing was changed to the BSD license. The software is now widely used and, for example, serves billions of users a month on Facebook and Wikipedia alone .

functionality

The connection to such a server takes place via the protocols TCP and IP . Data is given a unique key value (comparable to the name of a variable ) and stored as character strings in the working memory. In order to enable the storage of data types such as whole or floating point numbers as well as objects , this data is serialized in advance by most program libraries .

Data can either be saved permanently or temporarily. In the latter case, memcached takes care of the deletion automatically.

Examples

PHP

// Verbindung herstellen
$memcached = @memcache_connect('localhost', 11211)
             or die('FEHLER! Die Verbindung zum Server ist fehlgeschlagen!');

// Die Zeichenkette 'Hallo' unter der Bezeichnung 'wert1'
// für 1800 Sekunden abspeichern
$memcached->add('wert1', 'Hallo', false, 1800);

// Die Zeichenkette 'Hallo, nochmal' unter der Bezeichnung 'wert2'
// dauerhaft (Wert 0) in komprimierter Form abspeichern
$memcached->add('wert2', 'Hallo, nochmal', MEMCACHE_COMPRESSED, 0);

// 'wert1' löschen
$memcached->delete('wert1');

// 'wert2' mit dem Ganzzahlenwert 5979 ersetzen und für 23979 Sekunden
// unkomprimiert abspeichern. Vorhandene Werte müssen mit replace() überschrieben
// werden. Eine Verwendung von add() würde in einem solchen Fall zu einem
// Fehler führen!
$memcached->replace('wert2', 5979, false, 23979);

// 'wertObjekt' für 10 Sekunden mit dem Wert einer Instanz der PHP-Klasse
// stdClass anlegen
$memcached->add('wertObjekt', new stdClass(), false, 10);

// das gespeicherte Objekt von 'wertObjekt' ausgeben
echo var_export($memcached->get('wertObjekt'), true);

// sämtliche Statistiken, die der Server zur Verfügung stellt, ausgeben
var_dump($memcached->getStats());

// alle Werte löschen
$memcached->flush();

// Verbindung wieder schließen
$memcached->close();

Pearl

use Modern::Perl;
use Cache::Memcached::Fast;

# neues memcached-Objekt erzeugen
#
my $cache = Cache::Memcached::Fast->new({ servers => [ '127.0.0.1:11211', '192.168.50.55:11211' ] });

# ein einfaches key/value Paar speichern
#
$cache->set( 'key', 'value' );

# komplexe Datenstrukturen speichern
#
$cache->set( 'key', { name => 'John', age => 22 } );

# gespeicherte Daten abfragen
#
my $data = $cache->get( 'key' );

# einen Datensatz löschen
#
$cache->delete( 'key' );

# alle Werte löschen
#
$cache->flush_all;

# Verbindung schließen
#
$cache->disconnect_all;

Java

// Liste für die Server erstellen
List<InetSocketAddress> memcachedServers = new ArrayList<InetSocketAddress>();
memcachedServers.add( new InetSocketAddress("localhost",11211) );

// Verbindung herstellen
MemcachedClient memcachedClient = new MemcachedClient(memcachedServers);

// Die Zeichenkette "Hallo" für eine Stunde (3600 Sekunden) unter der Bezeichnung "wert1" abspeichern
memcachedClient.add("wert1", 3600, "Hallo");

// "wert1" löschen
memcachedClient.delete("wert1");

// alle Werte löschen
memcachedClient.flush()

Abuse as a DDoS tool

Memcached servers accessible from the public Internet can be used by attackers to reinforce denial-of-service attacks. Since the response to a memcached request is usually significantly larger than the request, the attacker can, as with a DNS amplification attack , increase the amount of data sent to the target. This attack technique was used during an attack on github.com at the end of February 2018 in order to achieve the highest data rate ever observed in a DDoS attack.

Misuse is only excluded with memcached servers that are behind a firewall. According to experts, it will take several months to identify the unprotected servers.

Web links

Program libraries

Software that uses memcached

Individual evidence

  1. Release 1.6.6 . May 13, 2020 (accessed May 13, 2020).
  2. InfoQ: JGroups Implementation of Memcached Supports Failover and JMX . (accessed on June 23, 2017).
  3. Record DDoS attack with 1.35 terabits per second against Github.com. In: heise Security. Retrieved on March 5, 2018 (German).
  4. These DDoS attacks break all records . Spiegel Online , March 8, 2018; accessed on March 9, 2018