开源 ERP 软件 Odoo 提速指南
ERP Odoo openerp
![speed up odoo](/data/attachment/album/201703/14/100026rz44ja8lzpryj474.jpg)


Odoo 是最流行的 ERP（企业资源计划）软件，它由 Python 编写，使用 PostgreSQL 作为后端数据库。Odoo 社区版是免费的开源软件，它囊括了项目管理，生产、财务、记账和销售管理，仓储管理，人力资源管理，甚至还有更多项目。里面包含了 30 个核心模块，以及超过 3000 个社区模块。Odoo 部署了大量的模块，数据库里也包含了庞大的数据等等，这些都使得这个软件比较复杂，可能会导致效率低下。Odoo 的两个主要瓶颈在于磁盘访问，以及数据库查询时间。


为了提升 Odoo 实例的性能，你可以：


* 使用一个快速磁盘驱动器来存储（最好是 SSD）。
* 使用[内存充足的 Linux VPS](https://www.rosehosting.com/linux-vps-hosting.html)。
* 在 Odoo 中激活<ruby> 多处理器模式 <rt>  multiprocessing mode </rt></ruby>。
* 正确配置并优化 PostgreSQL 服务。


### 获得一台有着更多内存的 SSD VPS


正如我们先前提到的，随机磁盘访问速度是 Odoo 的主要瓶颈之一。因此，要确保 Odoo 部署在一台[基于 SSD 的 VPS](https://www.rosehosting.com/linux-vps-hosting.html) 上。由于 Odoo 是一个对资源十分敏感的应用，因此始终要把它安装在一台有着更多 RAM 的 VPS 上，如果可能，将整个 Odoo 实例及其数据库加载到 RAM 中。固态磁盘驱动器尤其以随机存取见长，而且由于 SSD 没有任何活动部件，它们能够取得数百倍于传统机械硬盘驱动器的随机存取 IOPS（LCTT译注：即每秒读写操作的次数）。如果服务器没有采用 SSD 来驱动或提速，那么不管你对 Odoo 做多少优化和配置都无济于事，它仍然会很慢。所以，获得正确的主机来部署 Odoo 是提升其性能的最重要因素。


其它 Odoo 优化包括：


### 在 Odoo 配置中启用多处理器选项


要实现此功能，请定位到 openerp-server 二进制文件：



```
#updatedb
#locate openerp-server

/usr/bin/openerp-server

```

执行以下命令：



```
#/usr/bin/openerp-server --help

```

该命令的输出结果如下：



```
Usage: openerp-server [options]

Options:
  --version             show program's version number and exit

  (...)

  Multiprocessing options:
    --workers=WORKERS   Specify the number of workers, 0 disable prefork mode.
    --limit-memory-soft=LIMIT_MEMORY_SOFT
                        Maximum allowed virtual memory per worker, when
                        reached the worker be reset after the current request
                        (default 671088640 aka 640MB).
    --limit-memory-hard=LIMIT_MEMORY_HARD
                        Maximum allowed virtual memory per worker, when
                        reached, any memory allocation will fail (default
                        805306368 aka 768MB).
    --limit-time-cpu=LIMIT_TIME_CPU
                        Maximum allowed CPU time per request (default 60).
    --limit-time-real=LIMIT_TIME_REAL
                        Maximum allowed Real time per request (default 120).
    --limit-request=LIMIT_REQUEST
                        Maximum number of request to be processed per worker
                        (default 8192).

```

工作进程的数量应该和分配到 VPS 的 CPU 核心数一样，或者，如果你想为 PostgreSQL 数据库、cron 任务、或者其它和 Odoo 实例安装在同一台 VPS 上的其它应用预留出一些 CPU 核心，那么你可以将工作进程数设置为一个比 VPS 上可用 CPU 核心更低的值，以避免资源耗尽。


`limit-memory-soft` 和 `limit-memory-hard` 参数不言自明，你可以使用默认值，也可以根据 VPS 上的实际可用 RAM 来进行修改。


例如，如果你的 VPS 有 8 个 CPU 核心，以及 16 GB 内存，那么你可以将工作进程数设置为 17（CPU 核心数 x 2 + 1），`limit-memory-soft` 总值设置为 640 x 17 = 10880 MB，而 `limit-memory-hard` 总数设置为 68MB x 17 = 13056 MB，这样，Odoo 就会有总计达 12.75 GB 的 RAM。


例如，在一台拥有 16 GB RAM 和 8 个 CPU 核心的 VPS 上，编辑 Odoo 配置文件（如 `/etc/odoo-server.conf`），并添加以下行：



```
vi /etc/odoo-server.conf

```


```
workers = 17

limit_memory_hard = 805306368

limit_memory_soft = 671088640

limit_request = 8192

limit_time_cpu = 60

limit_time_real = 120

max_cron_threads = 2

```

别忘了重启 Odoo 让修改生效。


### 正确配置并优化 PostgreSQL


对于 PostgreSQL 优化，及时将它更新到最新版本是一个不错的主意。在 PostgreSQL 配置文件（`pg_hba.conf`）中，有两个设置需要修改：`shared_buffers` 和 `effective_cache_size`。将 `shared_buffers` 设置为可用内存的 20%，`effective_cache_size` 设置为可用内存的 50%。


例如，如果 Odoo 安装到了一台 16 GB RAM 的 SSD VPS 上，那么在 `pg_hba.conf` 中使用如下设置：



```
vi /var/lib/postgresql/data/pg_hba.conf
```


```
shared_buffers = 3072MB
effective_cache_size = 8192MB

```

重启 PostgreSQL 服务来让修改生效。


同时，也别忘了周期性手动执行 ‘**[VACUUM](https://wiki.postgresql.org/wiki/Introduction_to_VACUUM,_ANALYZE,_EXPLAIN,_and_COUNT)**’。此操作会将陈旧或临时数据清理干净，但请牢记，它会大量占用 CPU 和磁盘使用。




---


via: <https://www.rosehosting.com/blog/how-to-speed-up-odoo/>


作者：[rosehosting.com](https://www.rosehosting.com/) 译者：[GOLinux](https://github.com/GOLinux) 校对：[jasminepeng](https://github.com/jasminepeng)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
Odoo is the most popular ERP (Enterprise Resource Planning) software, written in Python and uses PostgreSQL as database back-end. The Odoo community edition is a free and [open source](https://www.rosehosting.com/blog/best-open-source-hosting-control-panels/) software which includes project management, manufacturing, accounting, billing and sales management, warehouse management, human resources and more. There are about 30 core modules and more than 3000 community modules. Odoo is a complex software, and deploying a number of modules, having huge data inside the database etc. could induce a slowdown. The two major Odoo bottlenecks are disk access and database query time. In this tutorial we will show you how how to speed up Odoo.


In order to increase the performance of an Odoo instance, make sure to use:

- a fast disk drive for storage (preferably SSD)
- a
[Linux VPS with lots of RAM](https://www.rosehosting.com/blog/what-is-linux-vps-hosting/). - activate multiprocessing mode in Odoo.
- configure and optimize the PostgreSQL service properly.

Table of Contents

## 1. Get an SSD VPS with more RAM

Like we mentioned previously, the random disk access speed is one of the major Odoo bottlenecks, so make sure to host Odoo on an [SSD based VPS](https://www.rosehosting.com/managed-vps-hosting.html). Always install Odoo on a VPS with more RAM because Odoo is known as resource intensive application, and load the entire Odoo instance and its database into RAM if possible. Solid state disk drives excel especially in random access and they can achieve random access IOPS hundreds of times higher than conventional mechanical har disk drives because SSDs do not have any moving parts. No matter how much optimizations and configurations you do on your Odoo, if the server is not fast or powered by SSD, your Odoo will be slow. Getting the right hosting for your Odoo is the most important factor of your Odoo’s performance.

[ecko_alert color=”blue”]Did we mention that Odoo is a resource-hungry app? It seems so. But fear not, RoseHosting will provide you the ultimate solution – a performance-tailored [Odoo VPS](https://www.rosehosting.com/odoo-hosting.html) optimized to match your most demanding needs. Get an SSD VPS from us and find out what record-breaking Odoo speed really means. [/ecko_alert]

Other Odoo optimizations include:

## 2. Enable the Multiprocessing option in your Odoo configuration

To do so, locate the openerp-server binary file:

#updatedb #locate openerp-server /usr/bin/openerp-server

Run the following command:

#/usr/bin/openerp-server --help

The output of this command should be like this:

Usage: openerp-server [options] Options: --version show program's version number and exit (...) Multiprocessing options: --workers=WORKERS Specify the number of workers, 0 disable prefork mode. --limit-memory-soft=LIMIT_MEMORY_SOFT Maximum allowed virtual memory per worker, when reached the worker be reset after the current request (default 671088640 aka 640MB). --limit-memory-hard=LIMIT_MEMORY_HARD Maximum allowed virtual memory per worker, when reached, any memory allocation will fail (default 805306368 aka 768MB). --limit-time-cpu=LIMIT_TIME_CPU Maximum allowed CPU time per request (default 60). --limit-time-real=LIMIT_TIME_REAL Maximum allowed Real time per request (default 120). --limit-request=LIMIT_REQUEST Maximum number of request to be processed per worker (default 8192).

The number of workers should be equal to a number of CPU cores allocated to the VPS, or if you want to leave some CPU cores exclusively for the PostgreSQL database, cron jobs or other applications installed on the same VPS where the Odoo instance is installed and running, set the number of workers to a lower value than CPU cores available on the VPS to avoid resources exhaustion.

The limit-memory-soft and limit-memory-hard are self-explanatory, and you should leave them to the default value or modify them depending on the RAM available on the actual VPS.

For example, if you have a VPS with 8 CPU cores and 16 GB of RAM, the number of workers should be 17 (CPU cores * 2 + 1), total limit-memory-soft value will be 640 x 17 = 10880 MB , and total limit-memory-hard 768MB x 17 = 13056 MB, so Odoo will use maximum 12.75 GB of RAM.

For example, on a VPS with 16 GB of RAM and 8 CPU cores, edit the Odoo configuration file (e.g. /etc/odoo-server.conf), and add the following lines to it:

vi /etc/odoo-server.conf

workers = 17 limit_memory_hard = 13690208256 limit_memory_soft = 11408506880 limit_request = 8192 limit_time_cpu = 60 limit_time_real = 120 max_cron_threads = 2

Do not forget to restart Odoo for the changes to take effect.

## 3. Properly configure and optimize PostgreSQL

As for the PostgreSQL optimization, it is a good idea to update to the latest PostgreSQL version whenever a new version comes out. There are two settings in PostgreSQL configuration file (pg_hba.conf) which should be modified: shared_buffers and effective_cache_size. Set shared_buffers to 20% of the available memory, and effective_cache_size to 50% of the available memory.

For example, if Odoo is installed on an SSD VPS with 16 GB of RAM, use the following settings in the postgresql.conf file:

vi /var/lib/postgresql/data/postgresql.conf

shared_buffers = 3072MB effective_cache_size = 8192MB

## 4. Restart PostgreSQL

Restart the PostgreSQL service for the changes to take effect.

## 5. Periodically clean up temporary data

Also, do not forget to run ‘[VACUUM](https://wiki.postgresql.org/wiki/Introduction_to_VACUUM,_ANALYZE,_EXPLAIN,_and_COUNT)‘ manually periodically. ‘Vacuuming’ cleans up stale or temporary data, but please keep in mind that it is heavy on both CPU and disk usage.

Of course, you don’t have to speed up Odoo, if you use one of our

[Odoo VPS Hosting](https://www.rosehosting.com/odoo-hosting.html) services, in which case you can simply ask our expert Linux admins to **speed up Odoo** for you. They are available 24×7 and will take care of your request immediately.

**PS.** If you liked this post, on how to speed up Odoo, please share it with your friends on the social networks using the sharing buttons or simply leave a reply below. Thanks.

Hi,

Thank You for this very helpful article. One question: Why we calculate number of workers by multiplying CPU core by 2, and then adding 1?

TIA,

ReplyAnes

That is the general Odoo rule of thumb.

ReplyAren’t the ‘limit_memory_soft’ and the ‘limit_memory_hard’ options set as virtual memory requirements PER worker and not the total memory requirement for ALL workers? Having read the ‘–help’ ouput the above is a bit confusing, just need some clarification.

ReplyOtherwise, some great tips, thank you!

Hi foks

This article is wrong . In the above you have set the soft limit per worker to 10.8 GB . With 17 workers thats alot more than the 16 GB on your box . Hard limit is also wrong .

You should review these figures .

Thanks

Antony

ReplyThe hard and soft limits are correct.

ReplyHi admin

I am afraid they are not .

–limit-memory-soft

Maximum allowed virtual memory per worker. If the limit is exceeded, the worker is killed and recycled at the end of the current request.

Defaults to 640MB.

You have a soft liit of 10.8 GB with 17 workers on a 16 GB server . You are out by a factor of ten .

ReplyHi admin,

Can you clarify about the limit-memory, are they applied PER worker or PER instance? According to odoo.py help page, they are applied per worker.

Thanks

ReplyHi Anes,

Yes, ‘limit-memory’ is the maximum allowed virtual memory per worker.

ReplyWays to speed up your Odoo site is really amazing blog as when one creates the site he has no idea of getting speed to its best so It really proves helpful and amazing for all of them.

ReplyPlease check your cron job. Try to run run it manually and see why it doesn’t stop.

ReplyIt does indeed seem the limits proposed are actually not correct. The parameters for memory limits are per worker. Yet the proposed setting gives the total for all the workers. If you multiply this by the number of workers you exceed the actual RAM available. Otherwise helpful article. Thanks!

ReplyThanks a ton for very helpful blog with details information.it will be good to know that when I’m running odoo server with workers error of ” bus.bus unavailable ” coming continuously.any idea of that ?

ReplyHi Dipak,

If you had a face about bus.bus unavailable is because the system has activated worker > 0, or you open the longpolling port but there is no services to handle that. By activating worker, the system let longpolling port is also active, so you need to third party services to handle that, for example is like nginx, In nginx you can configured to handle port of longpolling, (openerp-gevent), This is to handle IM Bus for Odoo Chat

Thanks

ReplyHi Admin, the rule of thumbs to calculate the worker just for processor multi thread or we could use it for processor not multi thread ?

ReplyThe multiprocessing mode is enabled whenever the worker count is not 0. If you want to run Odoo in multithreaded mode, you will need to leave the worker count to 0, and if you want to enable multiprocessing mode, you will need to set the number of workers higher than 0.

You can still enable multiprocessing mode even with 1 CPU core. The calculation rule

Reply`(CPU cores * 2 + 1)`

still applies.