SlideShare uma empresa Scribd logo
1 de 34
Baixar para ler offline
MEMCACHED
An Overview
Quick overview and best practices
- Asif Ali / Oct / 2010 / azifali@gmail.com
Image courtesy: memcached offical website
“The Disk is the new tape!”
Quoted from somewhere
What is memcache?
• Simple in memory caching system
• Can be used as a temporary in-memory data
store
• Stores data in-memory only.
• Excellent read performance.
• Great write performance.
• Data distribution between multiple servers.
• API available for most languages
Memcache
• NO – acid, data structures, etc etc.
• If you’re looking for a replacement for your DB
then you’re looking at the wrong solution.
• Simple “put” a data using a key
• Get the data using the key.
• Generally, your app remembers the key.
• Data typically expires or gets flushed out (so has a
short life).
• Does not auto commit to disk
When should I use memcached?
• When your database is optimized to the hilt and you
still need more out of it.
– Lots of SELECTs are using resources that could be better used
elsewhere in the DB.
– Locking issues keep coming up
• When table listings in the query cache are torn down
so often it becomes useless
• To get maximum “scale out” of minimum hardware
Use cases for memcached
• Anything what is more expensive to fetch from
elsewhere, and has sufficient hit rate, can be placed in
memcached
• Web Apps that require extremely fast reads
• Temporary data storage
• Global data store for your application data
• Session data (ROR)
• Extremely fast writes of any application data (that will
be committed to an actual data store later)
• Memcached is not a storage engine but a caching
system
NoSQL & SQL
• We’re not going to debate about the pros and
cons of the different NoSQL vs SQL solutions.
• My View: It really depends upon your requirements.
• NoSQL caters to large but specific problems and in
my opinion, there is no all in one solution.
• Your comfort of MySQL or SQL statements might not
solve certain scale problems
For Example
• If you have hundreds of Terra Bytes of data and would like to
process it, then clearly – Map Reduce + Hive would be a great
solution for it.
• If you have large data and would like to do real time analytics
/ queries where processing speed is important then you might
want to consider Cassandra / MongoDB
• If your app needs massive amounts of simple reads then
clearly memcached is probably the solution of choice
• If you want large storage of data with non aggregate
processing and very comfortable with MySQL then a MySQL
based sharded solution can do wonders.
MEMCACHED SERVER
Memcached Server Info
• Memcache server accepts read / write TCP
connections through a standalone app or daemon.
• Clients connect on specific ports to read / write
• You can allocate a fixed memory for memcached to
use.
• Memcached stores data in the RAM (of course!)
• Memcached uses libevent and scales pretty well
(theoritical limit 200,000)
Configuration options
• Max connections
• Threads
• Port number
• Type of process – foreground or daemon
• Tcp / udp
Read write (Pseudo code)
• Set “key”, “value”, ”expire time”
• A = get “key”
Sample Ruby code
• Connection:
– With one server:
M = MemCache.new ‘localhost:11211’, :namespace
=> ‘my_namespace’
– With multiple servers:
M = MemCache.new %w[one.example.com:11211
two.example.com:11211], :namespace =>
‘my_namespace’
Sample Ruby code
• Usage
– m = MemCache.new('localhost:11211')
– m.set 'abc', 'xyz‘
– m.get 'abc‘ => ‘xyz’
– m.replace ‘abc’, ‘123’
– m.get ‘abc’ => ‘123’
– m.delete ‘abc’ => ‘DELETED’
– m.get ‘abc’ => nil
Memcached data structure
• Generally simple strings
• Simple strings are compatible with other
languages.
• You can also store other objects example
hashes.
• Complex data stored using one language
generally may not be fetchable from different
systems
Sample Ruby code
• Memcache can store data of any data types.
– m = MemCache.new('localhost:11211')
– m.set ‘my_string’, ‘Hello World !’
– m.set ‘my_integer’, 100
– m.set ‘my_array’, [1,”hello”,”2.0”]
– m.set ‘my_hash’, {‘1’=>’one’,’2’=>’two’}
– m.set ‘my_complex_data’, <any complex data>
Limits of memcached
• Keys can be no more then 250 characters
• Stored data can not exceed 1M (largest typical slab
size) per key
• There are generally no limits to the number of nodes
running memcache
• There are generally no limits the the amount of RAM
used by memcache over all nodes
– 32 bit machines do have a limit of 4GB though
FEATURES
Memcached can replicate for high
availability
Memcached 1
Data structure A
Memcached 2
Copy of
Data structure A
Data can be distributed using
memcached
Memcached 1
Part 1 - Data
structure A
Memcached 2
Part - 2
The connecting client can connect to either memcached 1 or memcached 2 to
fetch any data that is distributed across the two servers
Memcached can store any object
• Simple String
• Hash
• Other
• Strings can be read / written among
heterogenous systems.
Memcached best practices
Best Practices
• Allocate enough space for memcached.
• Memcache does not auto save data into disk so don’t
forget to serialize your data if you need to.
• A memcached crash could lead to a large downtime
if you have to load a lot of data to load (into
memcache) so you should
– Replicate memcached data OR
– Find algorithms to store data as fast as you can OR
– Have redundant servers with similar data and handle “no
data” situation well.
Best Practices
• Shared nothing, non replicated set of servers works the best.
• Don’t try to replicate your database environment into
Memcached. It is not what it was meant for.
• Don’t store data for too long in memcached. Least recently
used items (LRU) are evicted automatically in certain
scenarios.
• Reload data that is required for your reads as often as
possible
• Don’t go just by existing benchmarks; Find out your
application benchmarks in your environment and use that
variable to scale.
What to look out for
• Memcached performance can hit roadblocks
under very high reads and writes on a single
instance so try to isolate read / write instances
or see what works best for your app.
• Data increments on memcache values –
remember this is a shared memory space and
data is not always “locked” before being
updated.
OUR MEMCACHED USAGE
Usage History
• Considered using memcached more than 2
years ago due to problems in high volumen
MySQL read and writes.
• Used it first as a way to store Mongrel’s
session variables instead of MySQL.
The Problem we tried to solve
• Deliver a matching ad to a complex set of variables
• 6000+ devices in device db.
• 8-10m records in ip data
• Country / carrier / manufacturer / channel / targeting
• IP filters, black lists
• Bot Filtering
• Ad moderation etc etc etc..
• Typical In an ad network scenario
The solution needed to
• Make data fetching as fast as possible
• Make data structures simple
• Make processing extremely simple (for
example a string comparision vs a SQL Query)
• Make processing of data as fast as possible.
• Complete all processing 50 ms or less.
..continued
• Using a database was possible in low traffic
scenario.
• Traffic grew and so did database nightmares.
Our usage of memcached
• Hundreds of millions of reads daily; small
chunks of data. Infrequent writes.
• More than 60G of memcached shared data
space.
• MySQL was fine until we moved our
performance metric from seconds to ms.
• Current total transaction time between 21-
50ms.
Our partial stack
Memcached clients currently used
• http://deveiate.org/code/Ruby-MemCache/
• http://github.com/higepon/memcached-client
• There are newer and better clients that can be
used.
Questions?

Mais conteúdo relacionado

Mais procurados

Java EE 7 Batch processing in the Real World
Java EE 7 Batch processing in the Real WorldJava EE 7 Batch processing in the Real World
Java EE 7 Batch processing in the Real WorldRoberto Cortez
 
Maria DB Galera Cluster for High Availability
Maria DB Galera Cluster for High AvailabilityMaria DB Galera Cluster for High Availability
Maria DB Galera Cluster for High AvailabilityOSSCube
 
Microservice Design Patterns.pdf
Microservice Design Patterns.pdfMicroservice Design Patterns.pdf
Microservice Design Patterns.pdfSimform
 
EWD 3 Training Course Part 1: How Node.js Integrates With Global Storage Data...
EWD 3 Training Course Part 1: How Node.js Integrates With Global Storage Data...EWD 3 Training Course Part 1: How Node.js Integrates With Global Storage Data...
EWD 3 Training Course Part 1: How Node.js Integrates With Global Storage Data...Rob Tweed
 
Hadoop Architecture and HDFS
Hadoop Architecture and HDFSHadoop Architecture and HDFS
Hadoop Architecture and HDFSEdureka!
 
Jenkins를 활용한 Openshift CI/CD 구성
Jenkins를 활용한 Openshift CI/CD 구성 Jenkins를 활용한 Openshift CI/CD 구성
Jenkins를 활용한 Openshift CI/CD 구성 rockplace
 
Introduction to Docker Compose
Introduction to Docker ComposeIntroduction to Docker Compose
Introduction to Docker ComposeAjeet Singh Raina
 
redis 소개자료 - 네오클로바
redis 소개자료 - 네오클로바redis 소개자료 - 네오클로바
redis 소개자료 - 네오클로바NeoClova
 
E tech vmware presentation
E tech vmware presentationE tech vmware presentation
E tech vmware presentationjpenney
 
MySQL/MariaDB Proxy Software Test
MySQL/MariaDB Proxy Software TestMySQL/MariaDB Proxy Software Test
MySQL/MariaDB Proxy Software TestI Goo Lee
 
오픈스택 기반 클라우드 서비스 구축 방안 및 사례
오픈스택 기반 클라우드 서비스 구축 방안 및 사례오픈스택 기반 클라우드 서비스 구축 방안 및 사례
오픈스택 기반 클라우드 서비스 구축 방안 및 사례SONG INSEOB
 
High Performance Mysql
High Performance MysqlHigh Performance Mysql
High Performance Mysqlliufabin 66688
 
Apache Jackrabbit Oak - Scale your content repository to the cloud
Apache Jackrabbit Oak - Scale your content repository to the cloudApache Jackrabbit Oak - Scale your content repository to the cloud
Apache Jackrabbit Oak - Scale your content repository to the cloudRobert Munteanu
 
Mapreduce by examples
Mapreduce by examplesMapreduce by examples
Mapreduce by examplesAndrea Iacono
 
[발표자료] 오픈소스 Pacemaker 활용한 zabbix 이중화 방안(w/ Zabbix Korea Community)
[발표자료] 오픈소스 Pacemaker 활용한 zabbix 이중화 방안(w/ Zabbix Korea Community) [발표자료] 오픈소스 Pacemaker 활용한 zabbix 이중화 방안(w/ Zabbix Korea Community)
[발표자료] 오픈소스 Pacemaker 활용한 zabbix 이중화 방안(w/ Zabbix Korea Community) 동현 김
 
MySQL User Group NL - MySQL 8
MySQL User Group NL - MySQL 8MySQL User Group NL - MySQL 8
MySQL User Group NL - MySQL 8Frederic Descamps
 
Introduction to Containers and Docker
Introduction to Containers and DockerIntroduction to Containers and Docker
Introduction to Containers and DockerFayçal Bziou
 
[OpenInfra Days Korea 2018] Day 2 - CEPH 운영자를 위한 Object Storage Performance T...
[OpenInfra Days Korea 2018] Day 2 - CEPH 운영자를 위한 Object Storage Performance T...[OpenInfra Days Korea 2018] Day 2 - CEPH 운영자를 위한 Object Storage Performance T...
[OpenInfra Days Korea 2018] Day 2 - CEPH 운영자를 위한 Object Storage Performance T...OpenStack Korea Community
 

Mais procurados (20)

Java EE 7 Batch processing in the Real World
Java EE 7 Batch processing in the Real WorldJava EE 7 Batch processing in the Real World
Java EE 7 Batch processing in the Real World
 
Maria DB Galera Cluster for High Availability
Maria DB Galera Cluster for High AvailabilityMaria DB Galera Cluster for High Availability
Maria DB Galera Cluster for High Availability
 
Microservice Design Patterns.pdf
Microservice Design Patterns.pdfMicroservice Design Patterns.pdf
Microservice Design Patterns.pdf
 
EWD 3 Training Course Part 1: How Node.js Integrates With Global Storage Data...
EWD 3 Training Course Part 1: How Node.js Integrates With Global Storage Data...EWD 3 Training Course Part 1: How Node.js Integrates With Global Storage Data...
EWD 3 Training Course Part 1: How Node.js Integrates With Global Storage Data...
 
Hadoop Architecture and HDFS
Hadoop Architecture and HDFSHadoop Architecture and HDFS
Hadoop Architecture and HDFS
 
Jenkins를 활용한 Openshift CI/CD 구성
Jenkins를 활용한 Openshift CI/CD 구성 Jenkins를 활용한 Openshift CI/CD 구성
Jenkins를 활용한 Openshift CI/CD 구성
 
Introduction to Docker Compose
Introduction to Docker ComposeIntroduction to Docker Compose
Introduction to Docker Compose
 
redis 소개자료 - 네오클로바
redis 소개자료 - 네오클로바redis 소개자료 - 네오클로바
redis 소개자료 - 네오클로바
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
E tech vmware presentation
E tech vmware presentationE tech vmware presentation
E tech vmware presentation
 
MySQL/MariaDB Proxy Software Test
MySQL/MariaDB Proxy Software TestMySQL/MariaDB Proxy Software Test
MySQL/MariaDB Proxy Software Test
 
오픈스택 기반 클라우드 서비스 구축 방안 및 사례
오픈스택 기반 클라우드 서비스 구축 방안 및 사례오픈스택 기반 클라우드 서비스 구축 방안 및 사례
오픈스택 기반 클라우드 서비스 구축 방안 및 사례
 
High Performance Mysql
High Performance MysqlHigh Performance Mysql
High Performance Mysql
 
Redis database
Redis databaseRedis database
Redis database
 
Apache Jackrabbit Oak - Scale your content repository to the cloud
Apache Jackrabbit Oak - Scale your content repository to the cloudApache Jackrabbit Oak - Scale your content repository to the cloud
Apache Jackrabbit Oak - Scale your content repository to the cloud
 
Mapreduce by examples
Mapreduce by examplesMapreduce by examples
Mapreduce by examples
 
[발표자료] 오픈소스 Pacemaker 활용한 zabbix 이중화 방안(w/ Zabbix Korea Community)
[발표자료] 오픈소스 Pacemaker 활용한 zabbix 이중화 방안(w/ Zabbix Korea Community) [발표자료] 오픈소스 Pacemaker 활용한 zabbix 이중화 방안(w/ Zabbix Korea Community)
[발표자료] 오픈소스 Pacemaker 활용한 zabbix 이중화 방안(w/ Zabbix Korea Community)
 
MySQL User Group NL - MySQL 8
MySQL User Group NL - MySQL 8MySQL User Group NL - MySQL 8
MySQL User Group NL - MySQL 8
 
Introduction to Containers and Docker
Introduction to Containers and DockerIntroduction to Containers and Docker
Introduction to Containers and Docker
 
[OpenInfra Days Korea 2018] Day 2 - CEPH 운영자를 위한 Object Storage Performance T...
[OpenInfra Days Korea 2018] Day 2 - CEPH 운영자를 위한 Object Storage Performance T...[OpenInfra Days Korea 2018] Day 2 - CEPH 운영자를 위한 Object Storage Performance T...
[OpenInfra Days Korea 2018] Day 2 - CEPH 운영자를 위한 Object Storage Performance T...
 

Destaque

ZestADZ Publisher Presentation
ZestADZ Publisher PresentationZestADZ Publisher Presentation
ZestADZ Publisher PresentationAsif Ali
 
An Overview of Hadoop
An Overview of HadoopAn Overview of Hadoop
An Overview of HadoopAsif Ali
 
The Future Of Mobile Advertising
The Future Of Mobile AdvertisingThe Future Of Mobile Advertising
The Future Of Mobile AdvertisingAsif Ali
 
Redis: servidor de estructuras de datos
Redis: servidor de estructuras de datosRedis: servidor de estructuras de datos
Redis: servidor de estructuras de datosAntonio Ognio
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcachedJurriaan Persyn
 
Aprendiendo REDIS en 20 minutos
Aprendiendo REDIS en 20 minutosAprendiendo REDIS en 20 minutos
Aprendiendo REDIS en 20 minutosGonzalo Chacaltana
 

Destaque (8)

ZestADZ Publisher Presentation
ZestADZ Publisher PresentationZestADZ Publisher Presentation
ZestADZ Publisher Presentation
 
An Overview of Hadoop
An Overview of HadoopAn Overview of Hadoop
An Overview of Hadoop
 
The Future Of Mobile Advertising
The Future Of Mobile AdvertisingThe Future Of Mobile Advertising
The Future Of Mobile Advertising
 
Redis: servidor de estructuras de datos
Redis: servidor de estructuras de datosRedis: servidor de estructuras de datos
Redis: servidor de estructuras de datos
 
In-Memory DataBase
In-Memory DataBaseIn-Memory DataBase
In-Memory DataBase
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
 
Aprendiendo REDIS en 20 minutos
Aprendiendo REDIS en 20 minutosAprendiendo REDIS en 20 minutos
Aprendiendo REDIS en 20 minutos
 
Curso completo de Elasticsearch
Curso completo de ElasticsearchCurso completo de Elasticsearch
Curso completo de Elasticsearch
 

Semelhante a Memcached Presentation

Membase Intro from Membase Meetup San Francisco
Membase Intro from Membase Meetup San FranciscoMembase Intro from Membase Meetup San Francisco
Membase Intro from Membase Meetup San FranciscoMembase
 
Scaling with sync_replication using Galera and EC2
Scaling with sync_replication using Galera and EC2Scaling with sync_replication using Galera and EC2
Scaling with sync_replication using Galera and EC2Marco Tusa
 
Storage Systems For Scalable systems
Storage Systems For Scalable systemsStorage Systems For Scalable systems
Storage Systems For Scalable systemselliando dias
 
Cloud computing UNIT 2.1 presentation in
Cloud computing UNIT 2.1 presentation inCloud computing UNIT 2.1 presentation in
Cloud computing UNIT 2.1 presentation inRahulBhole12
 
Eventual Consistency @WalmartLabs with Kafka, Avro, SolrCloud and Hadoop
Eventual Consistency @WalmartLabs with Kafka, Avro, SolrCloud and HadoopEventual Consistency @WalmartLabs with Kafka, Avro, SolrCloud and Hadoop
Eventual Consistency @WalmartLabs with Kafka, Avro, SolrCloud and HadoopAyon Sinha
 
Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetImproving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetAchieve Internet
 
Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetImproving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetAchieve Internet
 
Where Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsWhere Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsConcentric Sky
 
Hardware Provisioning
Hardware ProvisioningHardware Provisioning
Hardware ProvisioningMongoDB
 
M6d cassandrapresentation
M6d cassandrapresentationM6d cassandrapresentation
M6d cassandrapresentationEdward Capriolo
 
Maximizing performance via tuning and optimization
Maximizing performance via tuning and optimizationMaximizing performance via tuning and optimization
Maximizing performance via tuning and optimizationMariaDB plc
 
Maximizing performance via tuning and optimization
Maximizing performance via tuning and optimizationMaximizing performance via tuning and optimization
Maximizing performance via tuning and optimizationMariaDB plc
 
Navigating NoSQL in cloudy skies
Navigating NoSQL in cloudy skiesNavigating NoSQL in cloudy skies
Navigating NoSQL in cloudy skiesshnkr_rmchndrn
 
MongoDB: How We Did It – Reanimating Identity at AOL
MongoDB: How We Did It – Reanimating Identity at AOLMongoDB: How We Did It – Reanimating Identity at AOL
MongoDB: How We Did It – Reanimating Identity at AOLMongoDB
 
Best Practices for NoSQL Workloads on Amazon EC2 and Amazon EBS - February 20...
Best Practices for NoSQL Workloads on Amazon EC2 and Amazon EBS - February 20...Best Practices for NoSQL Workloads on Amazon EC2 and Amazon EBS - February 20...
Best Practices for NoSQL Workloads on Amazon EC2 and Amazon EBS - February 20...Amazon Web Services
 
Memcached B box presentation
Memcached B box presentationMemcached B box presentation
Memcached B box presentationNagesh Chinkeri
 

Semelhante a Memcached Presentation (20)

No sql exploration keyvaluestore
No sql exploration   keyvaluestoreNo sql exploration   keyvaluestore
No sql exploration keyvaluestore
 
Membase Intro from Membase Meetup San Francisco
Membase Intro from Membase Meetup San FranciscoMembase Intro from Membase Meetup San Francisco
Membase Intro from Membase Meetup San Francisco
 
Scaling with sync_replication using Galera and EC2
Scaling with sync_replication using Galera and EC2Scaling with sync_replication using Galera and EC2
Scaling with sync_replication using Galera and EC2
 
Memcached
MemcachedMemcached
Memcached
 
Storage Systems For Scalable systems
Storage Systems For Scalable systemsStorage Systems For Scalable systems
Storage Systems For Scalable systems
 
Cloud computing UNIT 2.1 presentation in
Cloud computing UNIT 2.1 presentation inCloud computing UNIT 2.1 presentation in
Cloud computing UNIT 2.1 presentation in
 
Eventual Consistency @WalmartLabs with Kafka, Avro, SolrCloud and Hadoop
Eventual Consistency @WalmartLabs with Kafka, Avro, SolrCloud and HadoopEventual Consistency @WalmartLabs with Kafka, Avro, SolrCloud and Hadoop
Eventual Consistency @WalmartLabs with Kafka, Avro, SolrCloud and Hadoop
 
Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetImproving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve Internet
 
Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetImproving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve Internet
 
Where Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsWhere Django Caching Bust at the Seams
Where Django Caching Bust at the Seams
 
Hardware Provisioning
Hardware ProvisioningHardware Provisioning
Hardware Provisioning
 
M6d cassandrapresentation
M6d cassandrapresentationM6d cassandrapresentation
M6d cassandrapresentation
 
Maximizing performance via tuning and optimization
Maximizing performance via tuning and optimizationMaximizing performance via tuning and optimization
Maximizing performance via tuning and optimization
 
Maximizing performance via tuning and optimization
Maximizing performance via tuning and optimizationMaximizing performance via tuning and optimization
Maximizing performance via tuning and optimization
 
Breaking data
Breaking dataBreaking data
Breaking data
 
Navigating NoSQL in cloudy skies
Navigating NoSQL in cloudy skiesNavigating NoSQL in cloudy skies
Navigating NoSQL in cloudy skies
 
No sql presentation
No sql presentationNo sql presentation
No sql presentation
 
MongoDB: How We Did It – Reanimating Identity at AOL
MongoDB: How We Did It – Reanimating Identity at AOLMongoDB: How We Did It – Reanimating Identity at AOL
MongoDB: How We Did It – Reanimating Identity at AOL
 
Best Practices for NoSQL Workloads on Amazon EC2 and Amazon EBS - February 20...
Best Practices for NoSQL Workloads on Amazon EC2 and Amazon EBS - February 20...Best Practices for NoSQL Workloads on Amazon EC2 and Amazon EBS - February 20...
Best Practices for NoSQL Workloads on Amazon EC2 and Amazon EBS - February 20...
 
Memcached B box presentation
Memcached B box presentationMemcached B box presentation
Memcached B box presentation
 

Último

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 

Último (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 

Memcached Presentation

  • 1. MEMCACHED An Overview Quick overview and best practices - Asif Ali / Oct / 2010 / azifali@gmail.com Image courtesy: memcached offical website
  • 2. “The Disk is the new tape!” Quoted from somewhere
  • 3. What is memcache? • Simple in memory caching system • Can be used as a temporary in-memory data store • Stores data in-memory only. • Excellent read performance. • Great write performance. • Data distribution between multiple servers. • API available for most languages
  • 4. Memcache • NO – acid, data structures, etc etc. • If you’re looking for a replacement for your DB then you’re looking at the wrong solution. • Simple “put” a data using a key • Get the data using the key. • Generally, your app remembers the key. • Data typically expires or gets flushed out (so has a short life). • Does not auto commit to disk
  • 5. When should I use memcached? • When your database is optimized to the hilt and you still need more out of it. – Lots of SELECTs are using resources that could be better used elsewhere in the DB. – Locking issues keep coming up • When table listings in the query cache are torn down so often it becomes useless • To get maximum “scale out” of minimum hardware
  • 6. Use cases for memcached • Anything what is more expensive to fetch from elsewhere, and has sufficient hit rate, can be placed in memcached • Web Apps that require extremely fast reads • Temporary data storage • Global data store for your application data • Session data (ROR) • Extremely fast writes of any application data (that will be committed to an actual data store later) • Memcached is not a storage engine but a caching system
  • 7. NoSQL & SQL • We’re not going to debate about the pros and cons of the different NoSQL vs SQL solutions. • My View: It really depends upon your requirements. • NoSQL caters to large but specific problems and in my opinion, there is no all in one solution. • Your comfort of MySQL or SQL statements might not solve certain scale problems
  • 8. For Example • If you have hundreds of Terra Bytes of data and would like to process it, then clearly – Map Reduce + Hive would be a great solution for it. • If you have large data and would like to do real time analytics / queries where processing speed is important then you might want to consider Cassandra / MongoDB • If your app needs massive amounts of simple reads then clearly memcached is probably the solution of choice • If you want large storage of data with non aggregate processing and very comfortable with MySQL then a MySQL based sharded solution can do wonders.
  • 10. Memcached Server Info • Memcache server accepts read / write TCP connections through a standalone app or daemon. • Clients connect on specific ports to read / write • You can allocate a fixed memory for memcached to use. • Memcached stores data in the RAM (of course!) • Memcached uses libevent and scales pretty well (theoritical limit 200,000)
  • 11. Configuration options • Max connections • Threads • Port number • Type of process – foreground or daemon • Tcp / udp
  • 12. Read write (Pseudo code) • Set “key”, “value”, ”expire time” • A = get “key”
  • 13. Sample Ruby code • Connection: – With one server: M = MemCache.new ‘localhost:11211’, :namespace => ‘my_namespace’ – With multiple servers: M = MemCache.new %w[one.example.com:11211 two.example.com:11211], :namespace => ‘my_namespace’
  • 14. Sample Ruby code • Usage – m = MemCache.new('localhost:11211') – m.set 'abc', 'xyz‘ – m.get 'abc‘ => ‘xyz’ – m.replace ‘abc’, ‘123’ – m.get ‘abc’ => ‘123’ – m.delete ‘abc’ => ‘DELETED’ – m.get ‘abc’ => nil
  • 15. Memcached data structure • Generally simple strings • Simple strings are compatible with other languages. • You can also store other objects example hashes. • Complex data stored using one language generally may not be fetchable from different systems
  • 16. Sample Ruby code • Memcache can store data of any data types. – m = MemCache.new('localhost:11211') – m.set ‘my_string’, ‘Hello World !’ – m.set ‘my_integer’, 100 – m.set ‘my_array’, [1,”hello”,”2.0”] – m.set ‘my_hash’, {‘1’=>’one’,’2’=>’two’} – m.set ‘my_complex_data’, <any complex data>
  • 17. Limits of memcached • Keys can be no more then 250 characters • Stored data can not exceed 1M (largest typical slab size) per key • There are generally no limits to the number of nodes running memcache • There are generally no limits the the amount of RAM used by memcache over all nodes – 32 bit machines do have a limit of 4GB though
  • 19. Memcached can replicate for high availability Memcached 1 Data structure A Memcached 2 Copy of Data structure A
  • 20. Data can be distributed using memcached Memcached 1 Part 1 - Data structure A Memcached 2 Part - 2 The connecting client can connect to either memcached 1 or memcached 2 to fetch any data that is distributed across the two servers
  • 21. Memcached can store any object • Simple String • Hash • Other • Strings can be read / written among heterogenous systems.
  • 23. Best Practices • Allocate enough space for memcached. • Memcache does not auto save data into disk so don’t forget to serialize your data if you need to. • A memcached crash could lead to a large downtime if you have to load a lot of data to load (into memcache) so you should – Replicate memcached data OR – Find algorithms to store data as fast as you can OR – Have redundant servers with similar data and handle “no data” situation well.
  • 24. Best Practices • Shared nothing, non replicated set of servers works the best. • Don’t try to replicate your database environment into Memcached. It is not what it was meant for. • Don’t store data for too long in memcached. Least recently used items (LRU) are evicted automatically in certain scenarios. • Reload data that is required for your reads as often as possible • Don’t go just by existing benchmarks; Find out your application benchmarks in your environment and use that variable to scale.
  • 25. What to look out for • Memcached performance can hit roadblocks under very high reads and writes on a single instance so try to isolate read / write instances or see what works best for your app. • Data increments on memcache values – remember this is a shared memory space and data is not always “locked” before being updated.
  • 27. Usage History • Considered using memcached more than 2 years ago due to problems in high volumen MySQL read and writes. • Used it first as a way to store Mongrel’s session variables instead of MySQL.
  • 28. The Problem we tried to solve • Deliver a matching ad to a complex set of variables • 6000+ devices in device db. • 8-10m records in ip data • Country / carrier / manufacturer / channel / targeting • IP filters, black lists • Bot Filtering • Ad moderation etc etc etc.. • Typical In an ad network scenario
  • 29. The solution needed to • Make data fetching as fast as possible • Make data structures simple • Make processing extremely simple (for example a string comparision vs a SQL Query) • Make processing of data as fast as possible. • Complete all processing 50 ms or less.
  • 30. ..continued • Using a database was possible in low traffic scenario. • Traffic grew and so did database nightmares.
  • 31. Our usage of memcached • Hundreds of millions of reads daily; small chunks of data. Infrequent writes. • More than 60G of memcached shared data space. • MySQL was fine until we moved our performance metric from seconds to ms. • Current total transaction time between 21- 50ms.
  • 33. Memcached clients currently used • http://deveiate.org/code/Ruby-MemCache/ • http://github.com/higepon/memcached-client • There are newer and better clients that can be used.