Resources

Performance Optimization Techniques for Odoo Development

Performance Optimization Techniques for Odoo Development

By default Odoo runs its multi-threaded server, and the multi-processing server only starts when you set the workers option to a non-zero number. A bigger machine with the default settings therefore does not behave the way people assume, because Python threads share one interpreter lock and do little work in parallel.

Is a slow Odoo a hardware problem?

Sometimes, but check the configuration first. Odoo’s deployment guide gives a rule of thumb of (number of CPUs x 2) + 1 as the maximum worker count, with each worker handling about 6 concurrent users. Cron workers need CPU too, so they come out of the same budget.

Worked example of Odoo worker sizing for 4 CPUs and 60 concurrent users

The guide’s own example is 4 CPUs and 60 users. Sixty users divided by 6 would call for 10 workers, but the formula caps it at 9, so the example settles on 8 workers plus 1 cron worker and keeps an eye on CPU load. Its memory estimate assumes 20% of requests are heavy (about 1 GB of RAM per worker) and 80% are light (about 150 MB), which comes to roughly 3 GB for that setup.

Those numbers assume well-written computed fields and SQL, and that is the part nobody can buy with a larger server.

Distance matters as well. If users are in another continent from the server, every click pays the round trip, and our article on routing Odoo users to the nearest server covers that case. Does your slowdown show up only for remote offices? Then no amount of RAM helps.

More caching does not fix a slow query

Odoo already caches inside its ORM and registry. Adding Redis or Memcached in front of an unchanged query scanning a large table moves the cost around without removing it, and I would skip bolt-on caches until profiling points at one.

Profiling

Odoo ships a profiler that records executed queries and stack traces. Turn on developer mode, enable profiling in the developer tools, and it records SQL and traces for the session by default. Results open in the speedscope flamegraph viewer, or you can store them as ir.profile records. From Python you can also wrap a block of code in the Profiler context manager and pass collectors such as sql. The profiler finds problems and fixes none of them, which sounds obvious until someone profiles for an afternoon and changes nothing.

Two details matter in practice.

  • Odoo Online databases cannot be profiled, so you need a copy on your own server
  • In Python tests, self.profile() combined with assertQueryCount lets you fail a build when a method starts issuing more queries than before

Run it on realistic data. A demo database with 200 records hides every problem a production one with 2 million shows.

Write ORM code that works in batches

Odoo’s performance guide lists batch operations, lower algorithmic complexity and indexes as its main good practices, and those three cover most of the code-level slowness in custom modules. The classic mistake is a search or a read inside a loop over records, which turns one query into thousands.

Fetch once, then work on the recordset. Create records in a single call with a list of values rather than one call per row. Fetch only the fields you need.

Obviously, fewer queries beat faster queries.

YouTube player

Database indexes are the other half. A field you search or sort on constantly, and that has no index, forces PostgreSQL to scan the whole table. Check the slowest queries from the profiler before adding any, because an index nobody uses still slows writes down.

The talk above, from Odoo’s own channel, covers PostgreSQL tuning.

Teams without Odoo experience in-house sometimes bring in an Odoo development company for this kind of review. If you are new to the platform itself, what Odoo ERP is and how to integrate it gives the background.

Order of attack

Profile first. Then fix workers and memory limits, then queries and loops, then indexes, and caching last. And test on a copy of production data, because a slow report that only appears at real volume will not show up anywhere else.

Bogdan Sandu

Stay sharp. Ship better code.

Every week: one curated article, one tool worth knowing, one tip you can use tomorrow. No noise, no padding.