redis tutoring

33
Redis Tutoring Blackie 2015/10/12

Upload: chen-tien-tsai

Post on 13-Feb-2017

610 views

Category:

Engineering


3 download

TRANSCRIPT

Page 1: Redis tutoring

Redis Tutoring

Blackie2015/10/12

Page 2: Redis tutoring

Redis IntroductionStackExchange.Redis IntroductionRedisDemo IntroductionTools

Page 3: Redis tutoring

Who am I

Blackie TsaiSenior IT consultant of Xuenn

Full stack developerMajor on development of real-time transaction system with low latency and high concurrentLearning CI&CD and run with Agile&LEAN

Bloghttp://www.dotblogs.com.tw/blackie1019

Page 4: Redis tutoring

REDIS INTRODUCTION

Page 5: Redis tutoring

Redis

Redis - A.K.A Remote Directory Server. It is an open source (BSD licensed), one of Key-Value database of NoSQL, in-memory data structure store, used as database, cache and message broker. It also can run atomic operations.Most Popular NoSQL(http://techstacks.io/)Recommend using Linux for deploying.Features

Pure SimpleSingle TreadIn-memory but persistent on disk databaseRemote dictionary server

3.0.4 is the latest stable version.

開源資料庫Redis實戰經驗大公開

Page 6: Redis tutoring

https://www.g2crowd.com/press-release/best-nosql-databases-fall-2015/

Page 7: Redis tutoring

https://clusterhq.com/assets/pdfs/state-of-container-usage-june-2015.pdf

Over 70% would like to run a database or other stateful service in their container environments, with MySQL and Redis the two leading choicesImportant features for data management in container solutions were:

Integration of data management capabilities into existing container work flow and toolsseamless movement of data between dev, test and production environments.

Page 9: Redis tutoring

http://redis.io/clients

Page 10: Redis tutoring

Redis - Data Persistence

MasterRedis

SlaverRedis

Persistence to Disk

Server A

Server B

Replication

IMPLEMENTING PERSISTENCE IN REDIS

• Master instance with no persistence• Slave instance with AOF enabled

Page 13: Redis tutoring

Redis - DataStore

http://redis.io/commands#stringhttp://redis.io/commands#hashhttp://redis.io/commands#sethttp://redis.io/commands#sorted_sethttp://redis.io/commands#list

Page 15: Redis tutoring

STACKEXCHANGE.REDIS INTRODUCTION

Page 16: Redis tutoring

Stack Exchange

The world’s largest programmingcommunity is growingStack Exchange is a network of 130+ Q&A communities including Stack OverflowGlobal traffic ranking 54th largest website

Page 17: Redis tutoring

Architecture of Stack Exchange

http://stackexchange.com/performance

Page 18: Redis tutoring

Stack Exchange - Info

Stack Overflow still uses Microsoft products.Stack Overflow still uses a scale-up strategy with HA.SQL Servers loaded with 384 GB of RAM and 2TB of SSD.Stats

4 million users, 8 million questions, 40 million answers, 560 million pageviews a month.Peak is more like 2600-3000 requests/sec on most weekdays. 25 servers, Stack Overflow has a 40:60 read-write ratio. 2 TB of SQL data all stored on SSDs, Each web server has 2x 320GB SSDs in a RAID 1.DB servers average 10% CPU utilization, 11 web servers, using IIS.2 load balancers, 1 active, using HAProxy4 active database nodes, using MS SQL2 machines for distributed cache and messaging using Redis2 read-only SQL Servers for used mainly for the Stack Exchange API3 machines doing search with ElasticSearch

Page 19: Redis tutoring

Stack Exchange - Caching

CachingCache all the things.

5 levels of caches.

1st: Caching in the browser, CDN, and proxies.

2nd: Using HttpRuntime.Cache. An in-memory,

per server cache.

3rd: Redis.

4th: SQL Server

Cache. 5th: SSD

.

Page 20: Redis tutoring

Stack Exchange - Lessons Learned

Why use Redis if you use MS products? gabeech: It's not about OS evangelism. We run things on the platform they run best on. Period. C# runs best on a windows machine, we use IIS. Redis runs best on a *nix machine we use *nix.

Overkill as a strategySSDs RockKnow your read/write workloadKeeping things very efficient means new machines are not needed oftenDon’t be afraid to specializeDo only what needs to be doneReinvention is OKGo down to the bare metal No bureaucracy.Garbage collection driven programmingThe cost of inefficient code can be higher than you think

Page 21: Redis tutoring

StackExchange.Redis

Basic Usage - getting started and basic usageConfiguration - options available when connecting to redisPipelines and Multiplexers - what is a multiplexer?Keys, Values and Channels - discusses the data-types used on the APITransactions - how atomic transactions work in redisEvents - the events available for logging / information purposesPub/Sub Message Order - advice on sequential and concurrent processingScripting - running Lua scripts with convenient named parameter replacement

https://github.com/StackExchange/StackExchange.Redis

Page 22: Redis tutoring

How to use

Page 24: Redis tutoring

REDISDEMO INTRODUCTION

Page 25: Redis tutoring

RedisDemo

FeaturesConnection Mapping with ConfigurationConfiguration with Redis Instance Group and Name concept supportedSingleton pattern avoid resource waste

DependencyStackExchange.RedisFX.ConfigurationNewtonsoft.JsonLog4Net(Optional)

Demo Versionhttps://github.com/blackie1019/RedisDemo

Page 26: Redis tutoring

RedisDemo - Configuration

ConnectionSetting follow StackExchange.RedisConfigurationOptions.Parse()

Page 27: Redis tutoring

RedisDemo Framework - Example

Page 28: Redis tutoring

Example Lab

Example – Basic StringsListsSetsHashesSorted Sets

Example – AdvanceSortExpireHashSet, HashGetAll and HashDeletePub/SubPipelinesBatch

Example – Scripting

https://github.com/blackie1019/RedisDemo

Page 29: Redis tutoring

TOOLS

Page 30: Redis tutoring

Redis Data Management

Cross-platform redis desktop manager - desktop management GUI for mac OS X, Windows, Debian and Ubuntu.

http://redisdesktop.com

Page 31: Redis tutoring

Opserver

Monitoring Tool of Stack ExchangeServersSQL clusters/instancesRedisElastic searchException logsHaproxy

Page 32: Redis tutoring

Redis Server with Docker

Enable Virtualization Technology on Bios and install Docker ToolboxCreate a Docker container for RedisRun the serviceCreate your web application container

If any problem you can remove and setup againdocker-machine rm defaultdocker-machine --native-ssh create -d virtualbox default

Dockerizing a Redis service

Page 33: Redis tutoring

Reference

Scaling Stack Overflow (QCon NYC 2015)Redis, another step on the roadTypes of NoSQL databasesStackOverflow Update: 560M Pageviews A Month, 25 Servers, And It's All About PerformanceRedis 设计与实现《Redis 设计与实现》图片集