ajvb / kala

Modern Job Scheduler
MIT License
2.13k stars 187 forks source link

Locks causing slow response times on POST /job #150

Closed gwoo closed 7 years ago

gwoo commented 7 years ago

I created a jobdb with a few thousand entries.

for i in {1..2000}
do
  time curl localhost:8000/api/v1/job/ -d '{"command": "echo cool", "name": "test_job", "schedule": "R/2017-04-011T11:11:11-07:00/PT10S}'
done

Then continue to add more jobs in smaller increments. From time to time, a request would take >2s to complete.

I tracked the issue down to Persist holding the lock for an extended time. So, I started looking for a way to remove the locks. To solve the problem, I implemented a FreeJobCache that uses a thread safe, lock free hashmap: https://github.com/gwoo/kala/commit/a458d4c06c4a3552e550fdfeae7e7e2fc1a3d5ed

You can also see, I modified the rest of the source to use the FreeJobCache. All the tests passed, so this seemed like a good change.

Probably the best thing to do would be to modify MemoryJobCache with the code from FreeJobCache. I can work on a PR if that you are interested.

ajvb commented 7 years ago

Hey @gwoo,

Thanks for working on this. I'm a big fan of this change and would love a PR!

gwoo commented 7 years ago

@ajvb On it! Stay Tuned!

gwoo commented 7 years ago

Fixed by #157