Dzone Rc250 Memcached
Dzone Rc250 Memcached
Dzone Rc250 Memcached
250
GETTING STARTED WITH CONTENTS
Memcached
Introduction
What is Memcached?
Installing Memcached
Connecting To Your Memcached Server
BY JAMES SUGRUE
Common Commands...and more!
LIMITATIONS
There are four key limitations in memcached to keep in mind:
Once installed you can run memcached using the following command,
Try it today for Free
where d causes memcached to run as a daemon process:
the client retrieves the data from the MySQL database and then
PREPEND
stores the returned value in the cache, for efficient access in
Prepend this value before the first byte in an existing item. If the speci-
subsequent executions.
fied key does not exist, the command will fail.
COMMON COMMANDS
prepend key flags exptime bytes [noreply]
The following attributes are used across a number of the value
following commands:
changed since you last retrieved it (using gets) it will not be stored.
STATS SLABS
cas key flags exptime bytes unique_cas_token [noreply]
value Returns information about items stored in memcached, broken down
by slab id. Values returned in this command are more focused around
RETRIEVAL COMMANDS performance such as memory usage, allocated memory, and number
The following commands allow you to retrieve values from your of free chunks.
memcached store.
stats items
GET
Command for retrieving data for a given key, or set of keys. If a key STATS SIZES
does not exist, no value is returned. Illustrates how items would be distributed if broken into 32 byte
buckets instead of your current number of slabs, helping you to
get key [key2 .. keyn]
determine how efficient your slab sizing is.
GETS
stats sizes
Get command to be used with CAS, which returns the unique_cas_to-
ken with the item. ICommand for retrieving data for a given key, or set MEMCACHED TOOLS
of keys. If a key does not exist, no value is returned. Although some level of debugging is possible using the commands
listed above with the telnet client, there are a number of other tools
gets key [key2 .. keyn]
available to help monitor and troubleshoot your distributed mem-
cached setup. The following is a summary of the most popular tools:
DELETE
Removes an item from the cache if it exists. MEMCACHE-TOP
Link: https://code.google.com/archive/p/memcache-top/
delete key [noreply]
A lightweight proxy for memcached as well as Redis, built by Tip: Enable SASL on memcached by using the S flag on startup. Following
Twitter to reduce the number of open connections to cache servers. this, all commands require that authentication be successful before they are
Requests to a pool of memcached instances go through this proxy. issued on a connection.
Using two twemproxy instances, traffic can be directed to both a
pool of slaves, as well as a pool of master instances. To increase your memcached security beyond SASL, the following
should be considered:
PERFORMANCE BEST PRACTICES
Never run memcached as root. If someone did gain access to
Following these best practices will help you get the most
memcached and there was a security vulnerability, then they
from memcached:
would be able to compromise your machine and network.
1. From stats, take note of the evictions count, which shows
Use a firewall to limit which connections are open to the
the number of non-expired items that were removed from the
outside world. If you are running memcached on a single
cache to make space for new items. If this number is high, it
server, then you can bind the instance to localhost using the
indicates that the memory allocated for items storage is too low.
l parameter, restricting cache access to just that machine.
2. The default number of threads is 4, and for most cases should
not be changed. Using a single thread will be too slow, and
more than 8 threads can lead to high lock contention.
A B O U T T H E AU T H O R
JAMES SUGRUE is Chief Architect at Over-C, building mobile applications and services for managing compliance, using
NFC and Bluetooth sensors for proof of presence. James is an expert in Java and Swift, building everything from desktop
applications to high performance servers and mobile applications in Android and iOS.
James has been a Zone Leader at DZone since 2008, and has written many Refcardz, as well as a book on Backbone.js.
DZone communities deliver over 6 million pages each month to more than
3.3 million software developers, architects and decision makers. DZone offers
something for everyone, including news, tutorials, cheat sheets, research guides,
DZONE, INC. REFCARDZ FEEDBACK
feature articles, source code and more. "DZone is a developer's dream," says PC 150 PRESTON EXECUTIVE DR. WELCOME
[email protected]
Magazine. CARY, NC 27513
SPONSORSHIP
Copyright 2017 DZone, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval
888.678.0399 OPPORTUNITIES
system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior
919.678.0300 [email protected]
written permission of the publisher.