go && python event driven ml - pycon odessa · 2020-06-01 · go && python event...

57
Go && Python Event driven ML Lalafo case

Upload: others

Post on 14-Jul-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

Go && Python Event driven ML

Lalafo case

Page 2: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue
Page 3: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

How it all started

Part 1. The Phantom Menace

Page 4: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue
Page 5: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

StackOverflow: Ready to rescue

Page 6: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

200 RPM

Page 7: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue
Page 8: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

$

Feedback

Page 9: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

$

Feedback

Processes Monitoring

RAM - expiration?

Relational DB?

Page 10: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

Any issues there?1. Request monitoring (?)2. Hard to reason GPU usage (varies 3 to 7GB)3. ~5Gb RAM out of the box (scale?)4. Redis is in-memory storage (temporary)5. Threading != Parallel

Page 11: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

http://www.nooooooooooooooo.com/

Page 12: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

What if we split API and ML

Part 2. A new hope

Page 13: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

Requirements

Lalafo case

1. Single image/request processing time: < 2 seconds2. Visibility3. Persistence4. Scalability 5. Make it extendable for new features

a. Price predictionb. Similarity searchc. Segmentation

6. SDK friendly (well documented, tested etc)

Page 14: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

$

Feedback

Processes Monitoring

RAM - expiration?

Relational DB?

Page 15: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

After 2 months

API Listeners

Feedback

$

Page 16: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

Requirements

Lalafo case

1. Single image/request processing time: < 2 seconds2. Visibility - Decouple request and prediction3. Persistence 4. Scalability 5. Make it extendable for new features

a. Price predictionb. Similarity searchc. Segmentation

6. SDK friendly (well documented, tested etc)

Page 17: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

2 seconds per request

Part 3. The Empire Strikes Back

Page 18: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

4 seconds per request

API Listeners

1 second0.01 sec

Page 19: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

segmentio/kafka-go -> shopify/sarama

API Listeners

0.02 sec0.01 sec

Page 20: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

3 seconds per request

API Listeners

0.02 sec

0.3 second

0.3 second

Synchronous request

Page 21: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

How large is every image

Page 22: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

2.4 seconds per request

API Listeners

0.02 sec

Synchronous request

Page 23: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

2.4 seconds per request

API Listeners

0.02 sec

Synchronous request

Page 24: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

2 seconds per request

API Listeners

0.02 sec

Synchronous request

Add ThreadPool

Page 25: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

2 seconds per request

Success? Not yet

Page 26: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

3 seconds per request

API Listeners

0.02 sec

Page 27: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

3 seconds per request

API Listeners

0.02 sec

1 second and growing

Page 28: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

3 seconds per request

Page 29: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

2 seconds per request

Page 30: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

¯\_(ツ)_/¯

Page 31: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

2 seconds per request

API Listeners

0.02 sec

Page 32: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

200 RPM -> 1200 RPM

Page 33: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

2 seconds per request

API Listeners

0.02 sec

ScaleScale

Master -> Slave -> balancer

Topics -> Partitions

Page 34: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

< 1 second per request

Success? Not yet

Page 35: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue
Page 36: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

Out of 8Gb

Page 38: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

7.6 Gb -> 600 Mb

Page 39: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

1 second per request

Success? Not yet

Page 40: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

Back to 2, 5, 10 seconds per request

Page 41: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

Troubleshooting

API Listeners

0.02 sec

? ?

Page 42: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

Troubleshooting

API Listeners

0.02 sec

?

Page 43: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

Troubleshooting

API Listeners

0.02 sec

?175k records per request

Page 44: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

Troubleshooting

API Listeners

0.02 sec?

Page 45: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

Troubleshooting

API

Page 46: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

SELECT * FROM ads LIMIT 1

Page 47: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

25 seconds -> 0.02 seconds

Page 48: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

0.02 seconds -> 0.002 second

Page 49: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

Success? Not yet

Page 50: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

Faust 1.4.6: No latest offset

https://github.com/robinhood/faust

Page 51: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

3K images per minute 0_o

Page 52: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

Success? Not yet

Page 53: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

Issues to solve1. Occasional spikes in performance (GC, network latency)2. Message broker (Kafka rebalancing, offset etc)3. How to handle DB migrations4. Something we are not aware of yet

Page 54: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

Lessons learnt1. CPU bound tasks != IO bound (¯\_(ツ)_/¯)2. High coupling - low cohesion3. You need to know how to cook MongoDB4. Go is not that obvious and library reach as Python5. Simple != Easier6. Concurrency != Parallelism (obviously)

Page 55: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

< 1 second per request

Page 56: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

+ Live statistics from PostgreSQL

API Listeners

Page 57: Go && Python Event driven ML - Pycon Odessa · 2020-06-01 · Go && Python Event driven ML Lalafo case. How it all started Part 1. The Phantom Menace. StackOverflow: Ready to rescue

Thank you everyone

Success?