I have a VueJs front-end, a python Flask back-end and I'm using Google Firebase database..
In some tasks there is a progression bar that is showed to the user. In order to realize the bar, back-end writes progressive values into databases and front-end reads it.
I changed the back-end because it was too slow, so I pararelized some operations using multiprocessing.Pool. I had a good performance improvement, but now the progressive bar sometimes goes on and then come back because there are more processes that are accessing to db.
Here I create the pool:
i = 1
num_workers = multiprocessing.cpu_count()
pool = multiprocessing.Pool(processes=num_workers)
for filename in glob.glob(os.path.join(files_path, '*')):
pool.apply_async(create_single_model, (filename, models_path, num_model_photos, uid, i))
print('Process: ' + str(i))
i = i + 1
The in create_single_model
I pass i
and increment it, but I think it's not correct.:
.
some operations...
.
percentage = round((i / num_model_photos) * 100)
i = i + 1
ref = fb.db.collection('users').document(uid).get()
actual_percentage = ref.to_dict()['running']
if percentage != actual_percentage:
fb.db.collection('users').document(uid).set({
'running': percentage
}, merge=True)