İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
4634 Görünümler

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
Vazgeç
En İyi Yanıt

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
Vazgeç
Üretici

Thank you Ravi :)

İlgili Gönderiler Cevaplar Görünümler Aktivite
0
Ara 16
5759
0
Oca 25
569
0
Tem 23
2000
2
Şub 23
2653
0
Oca 23
1518