title: Semaphores in dask.distributed?
body: <p>I have a dask cluster with n workers and want the workers to do queries to the database. But the database is only capable of handling m queries in parallel where m &lt; n. How can I model that in dask.distributed? Only m workers should work on such a task in parallel. </p>
  
  <p>I have seen that distributed supports locks (<a href="http://distributed.readthedocs.io/en/latest/api.html#distributed.Lock" rel="noreferrer">http://distributed.readthedocs.io/en/latest/api.html#distributed.Lock</a>). But with that, I could do only one query in parallel, not m.</p>
  
  <p>Also I have seen that I could define resources per worker (<a href="https://distributed.readthedocs.io/en/latest/resources.html" rel="noreferrer">https://distributed.readthedocs.io/en/latest/resources.html</a>). But that does not fit also, as the database is independent from the workers. I would either have to define 1 database resource per worker (which leads to too much parallel queries). Or I would have to distribute m database resources to n workers, which is difficult on setting up the cluster and suboptimal in execution.</p>
  
  <p>Is it possible to define something like semaphores in dask to solve that?</p>