Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
4940 Widoki

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?

Awatar
Odrzuć
Najlepsza odpowiedź

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
 

Awatar
Odrzuć
Autor

Thank you Ravi :)

Powiązane posty Odpowiedzi Widoki Czynność
0
gru 16
6003
0
sty 25
1016
0
lip 23
2393
2
lut 23
3123
0
sty 23
1955