Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

At a previous job we did something similar but ended up having workers first poll another table to determine which tenant to query against. We called these items tokens and they represented a finite amount of dedicated thread time for processing a specific tenants’ queue.

What this looked like was a worker thread would first query the token table for which tenant to process eligible tasks from, and then update the token to take a timed lock and during that time would solely process eligible tasks from a specific tenant.

This has some nice properties:

1. You can scale different tenants using different amounts of tokens which means different but controlled amounts of thread time.

2. It allows for locality on your worker thread. Within a specific tenant the processing was usually similar so any shared resources could be cached and reused after polling for additional eligible tasks from the tenants queue.



Reminded me of the token bucket[1] algorithm. Good point about locality.

[1]: https://en.wikipedia.org/wiki/Token_bucket


I like this approach a lot, but I’m unsure about time based vs number of items based fairness. I guess it really depends on the application.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: