Monday, 9 May 2022

Understanding working of multiple gunicorn process

I have no knowledge of what I'm trying to understand, surfing the internet brought me here and now I need this in my code.

I use django-rest-framework, gunicorn, and Nginx.

Suppose I have 3 workers process of gunicorn setup.

and I have a very simple view that reads a value from the database, performs a different task that takes around 1 second, increments the value by 1, and saves it back to the database.

class CreateView():
    value = MyModel.objects.get(id=1).integerValueField
    otherTask() #takes around 1 second (assume)
    updatedValue = value + 1
    MyModel.objects.filter(id=1).update(integerValueField=updatedValue)
    return

Will this always work?

what if a different worker process of gunicorn is handling the request of concurrent users? If the database is updated (integerValueField field) by a different process in between reading the value and updating the value by some other worker process? Is this locked somehow to maintain integrity?

if I can get valid links to read more about the topic, will work well for me.



from Understanding working of multiple gunicorn process

No comments:

Post a Comment