2015-10-20 processed billions of job by using beanstalkd queue

23
[email protected] om Teddy Chan CEO & Co-Founder

Upload: aftership

Post on 15-Apr-2017

446 views

Category:

Technology


1 download

TRANSCRIPT

[email protected]

Teddy ChanCEO & Co-Founder

Shipment tracking APISupporting 290 310+ carriers

Free Shipping APIsSingle API for 5 19 carriers

BeanstalkdThe queue system processed billions of job

Why we love queue?

Queue

- Buffer

- Load Balancing

- Scale Horizontal

- Async process

BeanstalkdHow AfterShip use queue?

- Ten of millions of job per day

- Billions of job so far

- 4 beanstalkd servers (AWS m3.large)

- 4 down incidents in last 3 years

Beanstalkd ProtocolCharacteristics

- Guarantee FIFO

- Each job is uniquely assigned to one worker.

- Each connection can only reserve one job at a time

- Support jobs persistent (“-b” option)

- Support priority, delay, ttr (time to run), bury

- No HA

Queue systems

References:http://queues.io/http://www.sitepoint.com/message-queues-comparing-beanstalkd-ironmq-amazon-sqs/

Beanstalkd Amazon SQS

Server Setup Self Host Full Managed

Response Time single digit ms hundred ms

First In First Out (FIFO) Guarantee & unique Does not guarantee

Priority Yes No

Delay Yes Yes

Pub / Sub TCP pub/sub https polling

Beanstalkd ProtocolAction you can do

Status Description

put (with delay) Add a new job in the queue

reserve Take the job from queue

delete Delete the job after reserved.

bury Bury the job after reserved.

kick Kick the job from buried status to ready status.

release (with delay) Release the job back to ready status, after reserved it.The job id, pri, will be same.

Beanstalkd ProtocolTypical life cycle for a job

put --------> [READY] -------> [RESERVED]-------> *proof*

Ready Tube

Job 1

put

Beanstalkd ProtocolPut

put --------> [READY] -------> [RESERVED]-------> *proof*

Ready TubeJob 1

Beanstalkd ProtocolReserve

put reserve --------> [READY] -------> [RESERVED]-------> *proof*

Ready Tube

Job 1

reserve

Beanstalkd ProtocolDelete

put reserve delete--------> [READY] -------> [RESERVED]-------> *proof*

Ready Tube

Job 1

delete

Beanstalkd ProtocolBury

put reserve bury--------> [READY] -------> [RESERVED]-------> [BURIED]

Ready Tube

Job 1

buryBuried Tube

Beanstalkd ProtocolKick

put reserve bury--------> [READY] -------> [RESERVED]-------> [BURIED]

KICK

Ready Tube

kickBuried Tube

Job 1

Beanstalkd ProtocolDelay

Job 1

Job 2

Ready Job

Delay Job (with 3s)

Beanstalkd ProtocolDelay

Job 1

Job 2 Ready Job

Delay Job (After 3s)

Beanstalkd ProtocolFull picture of the life cycle

BeanstalkdLet’s do something fun

BeanstalkdSo how much?

- 15 servers @ USD0.05 / hr

- 2 workers @ 0.05 USD per hr

- some traffic… $0.12 / GB

BeanstalkdSo how much?

- 15 servers @ USD0.05 / hr

- 2 workers @ 0.05 USD per hr

- some traffic… $0.12 / GB

- $0.97 in total

http://www.slideshare.net/aftership

FAQ