SlideShare a Scribd company logo
CACHE
Cách build hệ thống
đáp ứng truy cập cao
Châu Nguyễn Nhật Thanh
Head of Game Backend and Cloud
VNG Corp.
Content
Client Internet
1
2
3
4
Server
Kernel
App
Server
6
7
8
5
9
How to scale
● Optimize at node
– Maximize the performances at node
● Scale to multiples nodes
– How to scale ?
● Scale UP
● Scale OUT
1.Client Problems
Client Internet
1
2
3
4
Server
Kernel
App
Server
6
7
8
5
9
1.Client Problems
Client Internet
1
2
3
4
Server
Kernel
App
Server
6
7
8
5
9
1. Client Problems
● Web browser (HTTP)
– Static contents: js, css , image, video
– JS, CSS, image:
● minify, merge
● Compress header
– Caching:
● Expires header
● Local storage
● JS caching
1. Client Problems
● Mobile client
– Local storage
– In app resources bundle
1. Client Problems
● Tools
– Profiling:
● Chrome dev tools
– Minifying:
● Webpack, gulp, elixir (Laravel)
– File serving:
● Nginx
1. Client Problems
● Profiling
1. Client Problems
● Minifying
– gulp –production
● File serving with expire header
location ~* .(?:ico|css|js|gif|jpe?g|png)$ {
expires 30d;
add_header Pragma public;
add_header Cache-Control "public";
}
2. Client to ISP
Client Internet
1
2
3
4
Server
Kernel
App
Server
6
7
8
5
9
2. Client to ISP
● CDN (Content Delivery Network)
– Redirect (302)
– DNS server
● Content in ISP DC
● Return IP of ISP near your devices
2. Client to ISP
2. Client to ISP Problems
3.ISP Problem
Client Internet
1
2
3
4
Server
Kernel
App
Server
6
7
8
5
9
3.ISP Problem
● Routing
– Internal ISP
– Cross ISP
● Capacity of lease line between 2 ISPs
● Traffic monitoring
– 3G/4G users
● Telco routing
4.ISP to DC Problem
Client Internet
1
2
3
4
Server
Kernel
App
Server
6
7
8
5
9
4.ISP to DC Problem
● Routing
– DC to ISP
– Internal DC
● FW
● Network hardware capability
● Cross product routing
– Bandwidth
– FW
– SDN ????
5.Server Problems
Client Internet
1
2
3
4
Server
Kernel
App
Server
6
7
8
5
9
5.Server Problems
● Network card
– Gigabits
– Fiber
– Virtualization support ???
● CPU
● RAM
● GPU
5.Server Problems
● Scale UP vs scale OUT
5.Server Problems
● How to load balancing between nodes
– HA Proxy
– Nginx
– F5
5.Server Problems
● HA Proxy config sample
backend web-backend
balance roundrobin
server web1 web1.yourdomain.com:80 check
server web2 web2.yourdomain.com:80 check
backend blog-backend
balance roundrobin
mode http
server blog1 blog1.yourdomain.com:80 check
5.Server Problems
● HA Proxy config sample
frontend http
bind *:80
mode http
acl url_blog path_beg /blog
use_backend blog-backend if url_blog
default_backend web-backend
6. Kernel Problems
Client Internet
1
2
3
4
Server
Kernel
App
Server
6
7
8
5
9
6. Kernel Problems
● Drivers for HW optimization
● Max fd
● IP forwarder
● Local FW
– Iptables
● Network IO multiplexing support ???
– EPOLL
● https://code.facebook.com/posts/938078729581886/impro
ving-the-linux-kernel-with-upstream-contributions/
7. Application Problems
Client Internet
1
2
3
4
Server
Kernel
App
Server
6
7
8
5
9
Cache hcm-topdev
7. Application Problems
7. Application Problems
● Data structures
– Array
– Hash map
– Linked list
==> how to use ???
7. Application Problems
● Caching
– Local Cache
● Use Data structure
– External Cache
● Memcache
● Redis
– Caching algorithm
● LRU
● FIFO
● ….
7. Application Problems
● Data serialize
– Text Protocol
● Json, XML
– Binary
● Thrift, Protobuff …
– Compression
● Snapy, ZIP, GZIP
7. Application Problems
● Local cache
– Create a hash map
● localCache = new HashMap();
– Serialize object need to be cached
● serializedObj = JSON.encode(obj);
– Compress data
● compressedObj = GZIP.compress(serializedObj);
– Put to hash cache
● localCache.put(key, compressedObj);
7. Application Problems
– Get from cache
● compressedObj = localCache.get(key);
– Decompress data
● serializedObj = GZIP.decompress(compressedObj);
– Deserialize
● obj = JSON.decode(serializedObj);
7. Application Problems
7. Application Problems
7. Application Problems
● Caching algorithm
– Memory is limit
– What to do when memory is full
– FiFO ( First In First Out)
● First item inserted will be removed first
7. Application Problems
– LRU (Least recent used)
http://www.topjavatutorial.com/wp-content/uploads/2016/04/LRU-Cache.png
7. Application Problems
● How to refresh cache
– Expires
– ????
8. Application to kernel problems
Client Internet
1
2
3
4
Server
Kernel
App
Server
6
7
8
5
9
8. Application to kernel problems
● Memory copy overhead
– Share mem
– Zero copy buffer
● IO multiplexing
– Blocking
● Process base
● Thread base
– Nonblocking
● EPOLL
● KQUEUE
● Use libevent
9.Cross Server Problems
Client Internet
1
2
3
4
Server
Kernel
App
Server
6
7
8
5
9
9.Cross Server Problems
● Cross platform RPC
– Thrift
– GRPC
– Memcache protocol
9.Cross Server Problems
● External Cache server
– Memcached
● Memory only
● Slab memory management
● Use libevent for scalable sockets
● Key/Value only
– Twemcache (twitter memcached)
● Heavy
● https://github.com/twitter/twemcache/wiki/Random-
Eviciton-vs-Slab-Automove
9.Cross Server Problems
Memcached Slabs
(http://charlee.li/memcached-002.html)
9.Cross Server Problems
● Redis
– Memory and disk
– Simple data structure support
● String, hash, sets, list, sorted sets
– Pub/Sub
– Lua scripts
– Support memcached protocol
– Cluster support
9.Cross Server Problems
● Redis data structures
https://image.slidesharecdn.com/kickingasswithredis-
120618095415-phpapp02/95/kicking-ass-with-redis-3-728.jpg
Thank you
● Q&A
● We are hiring!!!!
● thanhcnn@vng.com.vn

More Related Content

PDF
Sơ lược kiến trúc hệ thống Zing Me
PDF
Zing Me Real Time Web Chat Architect
PDF
Design a scalable site: Problem and solutions
PDF
IoT and developer chances
PDF
02 vng thanhnt-speedup_ntvv2_by_ph_pextmodule_
PDF
kranonit S06E01 Игорь Цинько: High load
PDF
Zingme practice for building scalable website with PHP
PDF
Cache hcm-topdev
Sơ lược kiến trúc hệ thống Zing Me
Zing Me Real Time Web Chat Architect
Design a scalable site: Problem and solutions
IoT and developer chances
02 vng thanhnt-speedup_ntvv2_by_ph_pextmodule_
kranonit S06E01 Игорь Цинько: High load
Zingme practice for building scalable website with PHP
Cache hcm-topdev

What's hot (14)

PDF
Screaming Fast Wpmu
PDF
Web Performance Part 3 "Server-side tips"
PDF
WordCamp RVA
PDF
How to Monitor MySQL
PDF
Optimising for Performance
PDF
Web performance optimization - MercadoLibre
PDF
04 web optimization
PDF
From nothing to a video under 2 seconds / Mikhail Sychev (YouTube)
PDF
Integrating Node.js with PHP
PDF
From One to a Cluster
PDF
Full stack development
PDF
Redis : Database, cache, pub/sub and more at Jelly button games
PPTX
PHP and node.js Together
ODP
Mailerqnewpresentation
Screaming Fast Wpmu
Web Performance Part 3 "Server-side tips"
WordCamp RVA
How to Monitor MySQL
Optimising for Performance
Web performance optimization - MercadoLibre
04 web optimization
From nothing to a video under 2 seconds / Mikhail Sychev (YouTube)
Integrating Node.js with PHP
From One to a Cluster
Full stack development
Redis : Database, cache, pub/sub and more at Jelly button games
PHP and node.js Together
Mailerqnewpresentation
Ad

Similar to Cache hcm-topdev (20)

PDF
Optimizing Your Frontend Performance
PDF
7 Habits of Exceptional Performance
PDF
getting started with varnish
PDF
Varnish - PLNOG 4
PDF
Massively Scaled High Performance Web Services with PHP
PPTX
Joomla! Performance on Steroids
PDF
20 tips for website performance
PPT
Roy foubister (hosting high traffic sites on a tight budget)
PDF
Zingme practice for building scalable website with PHP
PDF
01 zingme practice for building scalable website with php
PDF
zingmepracticeforbuildingscalablewebsitewithphp
PPTX
Scylla on Kubernetes: Introducing the Scylla Operator
PDF
High Performance Drupal
PPTX
Maximizing PHP Performance with NGINX
PDF
ASP.NET Scalability - DDD7
ODP
Intro to XPages for Administrators (DanNotes, November 28, 2012)
PDF
The 5 most common reasons for a slow WordPress site and how to fix them – ext...
PDF
CTU June 2011 - Things that Every ASP.NET Developer Should Know
PDF
ASP.NET Scalability - NxtGen Oxford
ODP
oVirt DR Site to-site using ansible
Optimizing Your Frontend Performance
7 Habits of Exceptional Performance
getting started with varnish
Varnish - PLNOG 4
Massively Scaled High Performance Web Services with PHP
Joomla! Performance on Steroids
20 tips for website performance
Roy foubister (hosting high traffic sites on a tight budget)
Zingme practice for building scalable website with PHP
01 zingme practice for building scalable website with php
zingmepracticeforbuildingscalablewebsitewithphp
Scylla on Kubernetes: Introducing the Scylla Operator
High Performance Drupal
Maximizing PHP Performance with NGINX
ASP.NET Scalability - DDD7
Intro to XPages for Administrators (DanNotes, November 28, 2012)
The 5 most common reasons for a slow WordPress site and how to fix them – ext...
CTU June 2011 - Things that Every ASP.NET Developer Should Know
ASP.NET Scalability - NxtGen Oxford
oVirt DR Site to-site using ansible
Ad

Recently uploaded (20)

PPT
Ethics in Information System - Management Information System
PPTX
t_and_OpenAI_Combined_two_pressentations
PDF
📍 LABUAN4D EXCLUSIVE SERVER STAR GAMING ASIA NO.1 TERPOPULER DI INDONESIA ! 🌟
PPT
250152213-Excitation-SystemWERRT (1).ppt
PDF
simpleintnettestmetiaerl for the simple testint
PDF
Uptota Investor Deck - Where Africa Meets Blockchain
PDF
Slides PDF: The World Game (s) Eco Economic Epochs.pdf
PPTX
Mathew Digital SEO Checklist Guidlines 2025
PPTX
Funds Management Learning Material for Beg
PDF
SlidesGDGoCxRAIS about Google Dialogflow and NotebookLM.pdf
PDF
Smart Home Technology for Health Monitoring (www.kiu.ac.ug)
PDF
Introduction to the IoT system, how the IoT system works
PDF
📍 LABUAN4D EXCLUSIVE SERVER STAR GAMING ASIA NO.1 TERPOPULER DI INDONESIA ! 🌟
PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
PPT
FIRE PREVENTION AND CONTROL PLAN- LUS.FM.MQ.OM.UTM.PLN.00014.ppt
PPTX
1402_iCSC_-_RESTful_Web_APIs_--_Josef_Hammer.pptx
PPT
415456121-Jiwratrwecdtwfdsfwgdwedvwe dbwsdjsadca-EVN.ppt
PPT
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
PPTX
Layers_of_the_Earth_Grade7.pptx class by
PPTX
E -tech empowerment technologies PowerPoint
Ethics in Information System - Management Information System
t_and_OpenAI_Combined_two_pressentations
📍 LABUAN4D EXCLUSIVE SERVER STAR GAMING ASIA NO.1 TERPOPULER DI INDONESIA ! 🌟
250152213-Excitation-SystemWERRT (1).ppt
simpleintnettestmetiaerl for the simple testint
Uptota Investor Deck - Where Africa Meets Blockchain
Slides PDF: The World Game (s) Eco Economic Epochs.pdf
Mathew Digital SEO Checklist Guidlines 2025
Funds Management Learning Material for Beg
SlidesGDGoCxRAIS about Google Dialogflow and NotebookLM.pdf
Smart Home Technology for Health Monitoring (www.kiu.ac.ug)
Introduction to the IoT system, how the IoT system works
📍 LABUAN4D EXCLUSIVE SERVER STAR GAMING ASIA NO.1 TERPOPULER DI INDONESIA ! 🌟
The New Creative Director: How AI Tools for Social Media Content Creation Are...
FIRE PREVENTION AND CONTROL PLAN- LUS.FM.MQ.OM.UTM.PLN.00014.ppt
1402_iCSC_-_RESTful_Web_APIs_--_Josef_Hammer.pptx
415456121-Jiwratrwecdtwfdsfwgdwedvwe dbwsdjsadca-EVN.ppt
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
Layers_of_the_Earth_Grade7.pptx class by
E -tech empowerment technologies PowerPoint

Cache hcm-topdev