Odoo API data retrieval extremely slow and/or HTTP 502 Bad Gateway on Odoo API

I am retrieving sales orders and order lines from Odoo using Odoo.sale.order@odo and Odoo.sale.order_line@odo, but it is really slow. We have several hundred thousand lines per year.

I am also getting errors like:

itgenoda138
Le serveur Odoo agissait comme une passerelle ou un proxy et a reçu une réponse invalide du serveur en amont.
The remote server returned an error:
(502) Bad Gateway.

How can I improve the performance?

Odoo API Runtime Variations

Odoo seems recently to have fluctuations in performance. You can analyze them using the following script:

declare
  l_cnt number;
  l_id  number;
begin
  for i in 1..5
  loop
    select /*+ http_disk_cache(false) http_memory_cache(false) */ count(*)
    into l_cnt
    from odoo.sale.order@odo
    where create_date > trunc(sysdate) - 7
    ;
    select max(id)
    into   l_id
    from sessionios@datadictionary
    ;
    for r
    in 
    ( select duration_ms
      ,      url
      ,      public_query_parameters
      from sessionios@datadictionary
      where  id = l_id
    )
    loop
      dbms_output.put_line('Call #' || to_char(i) || ' on ' || r.url || ' took ' ||to_char(r.duration_ms) || ' ms, parameters: ' || r.public_query_parameters);
    end loop;
  end loop;
end;

This will run the same query five times and output the duration of only the API-call (so the Invantive infrastructure adds little to almost no extra duration).

When you see variations larger than 2,5x in a time frame, you might want to consult your Odoo partner whether additional resources can be made available.

When an individual Odoo API call takes more than the default 57 seconds, it will timeout and return a timeout error, which can include 502 Bad Gateway. AS a short term solution you might want to add a parameter to your Odoo connection string, like:

http-post-timeout-ms=312000

A 502 Bad Gateway seems to be occurring frequently on Odoo-hosted environments currently.

Limit Data Volume

There are various ways to improve performance of Odoo. The most efficient on Odoo thanks to it’s extensive support for filters, is to use server-side filtering (or as it is named on Power BI: “query folding”).

Just add a where-clause or filter step to your reports to select solely the data needed.

For more details, please refer to:

Deze vraag is automatisch gesloten na 2 weken inactiviteit. Het laatste gegeven antwoord is gemarkeerd als oplossing.

Gelieve een nieuwe vraag te stellen via een apart topic als het probleem opnieuw optreedt. Gelieve in de nieuwe vraag een link naar dit topic op te nemen door de URL er van in de tekst te plakken.

Dit topic is 7 dagen na het laatste antwoord automatisch gesloten. Nieuwe antwoorden zijn niet meer toegestaan.