Introduction

Problem Statement

Requirement

Traffic & Storage Estimation (Back of envelope calculation)

# jobs can be executed by one machine = (16 cores*2 threads)/ (5 minutes*60) = 0.10 jobs per second (or ~8000 jobs per day)

# of machines needed to run 1000 QPS = 1000/0.10 = 10000 (wow 😮 !)

A modern machine with 16 GB ram can hold up-to = (16 GB/5 MB * 5 minutes * 60) =10 jobs per second

# of machines needed to run 1000 QPS = 1000 / 10= 100

System interface

High Level design

Figure 1, job scheduler HLD, by Rakshesh Shah
Table: JOB

+------------------------------+--------+
| Attribute | Type |
+------------------------------+--------+
| user_id (partition key) | uuid |
| job_id (sort key) | uuid |
| actual_job_execution_time | date |
| job_status | string |
| job_type | string |
| job_interval | int |
| result_location | string |
| current_retries | int |
| max_retries | int |
| scheduled_job_execution_time | date |
| execution_status | string |
+------------------------------+--------+
Index: ScheduledJob+----------------------------------------------+------+
| Attribute | Type |
+----------------------------------------------+------+
| scheduled_job_execution_time (partition key) | time |
| job_id (sort key) | uuid |
+----------------------------------------------+------+
Query (SQL equivalent):SELECT * FROM ScheduledJob WHERE scheduled_job_execution_time == now() - X
Index: ScheduledJob

+----------------------------------------------+------+
| Attribute | Type |
+----------------------------------------------+------+
| scheduled_job_execution_time (partition key) | uuid |
| shard_id (partition key) | int |
| job_id (sort key) | uuid |
+----------------------------------------------+------+
Query (SQL equivalent):SELECT * FROM ScheduledJob WHERE scheduled_job_execution_time == now() - X and shard_id == Y

Deep Dive

Figure 2, job scheduler LLD, by Rakshesh Shah
worker 1:SELECT * FROM ScheduledJob WHERE scheduled_job_execution_time == now() - X and shard_id = 1worker 2:SELECT * FROM ScheduledJob WHERE scheduled_job_execution_time == now() - X and shard_id = 2
while True:
w = get_next_work()
do_work(w)

Conclusion

Reference

Logo

华为、百度、京东云现已入驻,来创建你的专属开发者社区吧!

更多推荐