- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2025 12:39 AM
Same thing here; job concurrency is good but nothing for task; some jobs we do have countless parallel tasks so by not controlling it the downstream servers goes to a grinding halt and tasks just terminate.
It needs what we call a spinlock on tasks to control the concurrency in a global shared space. If you case allows for a python wrapper we can do something like this:
1. Create a volume;
2. Ensure each task has a unique key of sorts; use a parameter;
3. Do a spinlock on the volume with something like this:
import time
import random
#############
# Concurrency
#############
aat_vol="/Volumes/{your_volume_path}"
aat=1
def saat(s):
time.sleep(1+random.randrange(1,10))
ready=False
while ready==False:
list=dbutils.fs.ls(aat_vol)
if len(list)<aat:
dbutils.fs.mkdirs(aat_vol+"/"+s)
ready=True
break
else:
time.sleep(1+random.randrange(1,10))
def eaat(s):
dbutils.fs.rm(aat_vol+"/"+s)
...
try:
eaat(target)
saat(target)
...
except Exception as e:
eaat(target)
raise e
eaat(target)aat_vol; is the path to your volume
aat: is the number of concurrent tasks you want to allow
saat: starts a task with the given key
eaat: ends a task with a given
The random is used to ensure they do not spin up on the same time in some cases 1/10 probability you will still have more than one initial spins; always ensure you call eaat to clear the volume even if it fails.