How to Shrink from 5 Tiers to 2 in a Multitier Microservices Architecture

Post on 22-Jan-2018

523 views 0 download

Transcript of How to Shrink from 5 Tiers to 2 in a Multitier Microservices Architecture

#nginx #nginxconf1

Hello,

My name is Vasiliy I am a Sr. Developer with My.com, Mail.Ru, Moscow HQ

How to Shrink from 5 Tiers to 2 in a Multitier Microservices Architecture

#nginx #nginxconf

• Introduction • How it works • Examples • Benchmarks

3

Agenda

#nginx #nginxconf4

CachesApplicationserver #1

Architecture

Applicationserver #N

Read-only slavesWrite-only master

Async replication

#nginx #nginxconf5

Tier 1 - NginXTier 2 - application server, some languageTier 3 - cache or cachesTier 4 - database proxyTier 5 - database server

Tiers

#nginx #nginxconf6

From 5 tiers to 2

database & database proxy

CachesApplication

server

ТTARANTOOL

Tarantoolupstream module

VS

#nginx #nginxconf7

Tier 1, 4 - NginXTier 2 - Tarantool, it is Lua application serverTier 3 - Tarantool, it is fast as cacheTier 5 - Tarantool, it is database with ACID transactions

Tiers

How it works

#nginx #nginxconf9

NginX & Tarantool

ТTARANTOOL

Tarantoolupstream module

JSON RPC or REST

MSGPack

#nginx #nginxconf

• Docker images• https://hub.docker.com/r/tarantool/tarantool-nginx • https://hub.docker.com/r/tarantool/tarantool • Packages• https://tarantool.org/download.html • Sources• https://github.com/tarantool • https://github.com/tarantool/nginx_upstream_module

10

Download NginX & Tarantool

#nginx #nginxconf11

Configure NginX

#nginx #nginxconf12

Create a function inside Tarantool

#nginx #nginxconf13

Launch Tarantool

#nginx #nginxconf14

1.$ wget '0.0.0.0:8081/api/do?arg_1=1&arg_2=2'2.$ cat do*{"id":0, "result": [ [“first"], [ { "request":{"arg_2":"2","arg_1":"1"} "1":"Goodbye world!" } ]]}

Get result

Some REST features

#nginx #nginxconf16

1.nginx.conf directive - tnt_http_rest_methods2.HOST:PORT/FUNCTION_NAME/PATH?ARGS3.FUNCTION_NAME is optional4.PATH and ARGS are optionals

REST

#nginx #nginxconf17

Add new location

#nginx #nginxconf18

Add new function

#nginx #nginxconf19

1.$ wget '0.0.0.0:8081/api_2/do?arg_1=1&arg_2=2'2.$ HTTP request sent, awaiting response... 405 Not Allowed

Try #1

#nginx #nginxconf20

1.$ wget '0.0.0.0:8081/api_2/do?arg_1=1&arg_2=2' \2. --post-data='{"params":["String", 1, [{"rest":"args"}]]}'3.$ cat do*{"id":0, "result": [[true]]}

Try #2

#nginx #nginxconf21

1.$ wget '0.0.0.0:8081/api_2/do?arg_1=1&arg_2=2' \2. --post-data='{"params":["String", 1, [{"rest":"args"}]]}'3.$ cat do*{"id":0,"error":{"message":"Duplicate key exists in <CUT>""code":-32771}}

Try #3

#nginx #nginxconf22

Get some dataNew NginX location

New function

#nginx #nginxconf23

1.$ wget '0.0.0.0:8081/get?str=String&num=1'2.$ cat get*{"id":0, "result":[ [1,"String",1,[{"rest":"args"}], {"method":"POST", … ]}

Get result

Some RPC features

#nginx #nginxconf25

1.If we are speaking in the context of NginX and Tarantool, the RPC and the REST are equal.

2.But, the FUNCTION_NAME has to be passed through json body.

RPC

#nginx #nginxconf26

Method nameNew NginX location

New function

#nginx #nginxconf27

1.$ wget '0.0.0.0:8081/tnt' \2. --post-data='{"method":"get_2", "params":["String", 1]}'3.$ cat get*{"id":0, "result":[ [1,”String",1,[{"rest":"args"}], {"method":"POST", … ]}

Get result

Some microservices examples

#nginx #nginxconf29

The architecture #1

Applicationserver #1

Applicationserver #N

ТTARANTOOL

database & database proxy

#nginx #nginxconf30

The architecture #2

ТTARANTOOL Application

server #N database

Applicationserver #N database

ТTARANTOOL

Applicationserver #N database

Sharding

Nativeproto

#nginx #nginxconf31

The architecture #3

Applicationserver #1

Applicationserver #N

ТTARANTOOL

Some DBMS

ТTARANTOOL

Mail.Ru benchmarks

Synthetic benchmarks. But, with real datasets.

#nginx #nginxconf34

Reads per second = ~20к

Read latency

#nginx #nginxconf35

Writes per second = ~10к

Write latency

Conclusion

#nginx #nginxconf

Thank You

37

facebook.com/vasiliy.soshnikov

linkedin.com/vasiliy-soshnikov

@vasayso