Skip to Content
Menu
This question has been flagged
1 Reply
4527 Views

Hi, I'm experiencing some inconsistency when working with http.Controller in a multi-worker environment.

Here's a very simplified controller to illustrate the problem:

class Test(http.Controller):
    def __init__(self):
        self.testing = {}
    @http.route('/test/', type='json', auth='user', website=True, methods=['POST'])
    def testing(self, **kw):
​        print(self.testing)
        self.testing[kw['id']] = kw['value']

The problem is that `self.testing` seem to contain different values at random times if the testing method is called relatively quickly. Seems like the workers are not syncing the value of self.testing fast enough or something. 

Any insights into how Odoo workers sync a Controllers cached properties?

Anybody had any similar issues?

Avatar
Discard
Best Answer

This behavior is normal :)

let me explain why this Inconsistent behavior in a multi-worker environment also knows as  Prefork Server.
When you start odoo with worker it creates multiple workers (HTTPWorker) using fork
those are the completely separate process you many think like a completely different server running parallel which can handle HTTP work. so one process/worker is busy other can handle new incoming Http request.

so insist behavior because there is no guarantee which worker handles your request and variable are not shared between process(workers) unlike in Threaded Server so worker returns stored value within it.

If you want to share data between multiple workers than either you have to save it database or filesystem.

so in your case save data in a database, the filesystem is completed one because you have to write boilerplate code read/write to file.

if data is very small then stored in request session (it's actually filesystem stored)
if data is like key/value pair and small then stored it in res.config 
if data is more complex then create transient model it's not persistence and will remove on vacuum cleanup
and the last option is stored in a normal model and save it forever
 

Avatar
Discard
Author

Thank you Ravi :)

Related Posts Replies Views Activity
0
Dec 16
5641
0
Jan 25
432
0
Jul 23
1890
2
Feb 23
2394
0
Jan 23
1364