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

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: