Make Pi-Hole to use all available CPUs

I'm using Pi-Hole for about 800 devices, running CentOS 7.5 64 bit, fully updated.
Every time I need a graph (Log Term Data/Graphics) or Top Lists (Log Term Data/Top Lists) it's too slow.

So, I changed the VM setings (Vsphere host) from 1 vCPU to 32 vCPU (!).
Even with 32 vCPU, looking at top utility, I noticed the Graphics or Top Lists was using 100% of one CPU only.
In this case, php-cgi is the program consuming 100% in one CPU only.

Memory it's not a problem too. From the configured 4GB, it's using only about 300MB.

I know Pi-Hole is also using third party tools behind the scenes (PHP, http server, etc).

Is there a way to improve the performance of the entire system to use all available power ?

Thanks.

The PHP web interface is not well optimized, but that's not the issue. The stats are retrieved from a database, and minimal work is done on the data after the database returns the stats. The database has to read the information from the disk and massage it according to the query it was given, which likely takes most of the time. This is not something that can be easily avoided, especially if you are trying to query for a large time range, as we do not control how fast your disk or the database driver is. Unless the database software can use multiple cores, we can not use multiple cores for the bulk of the processing. Throwing cores at a problem is not always a good solution anyways.

The upcoming API and new web interface should help with this in some ways, especially for the long term query log due to using server-side pagination.

1 Like

I don't have deep knowledge about how programs are built to use several CPUs at same time.

Then I read something about threads and/or multi core usage ([https://askleo.com/why-is-only-one-core-on-my-multi-core-processor-being-maxed-out/]).

[...]The software has to figure out how to best divide up the work...[...]In other words, the program needs to know to use multiple CPUs.[...]

If this article is correct, at first, my conclusion was php-cgi it's not prepared to use the CPU power available.
Going further, reading https://docs.pi-hole.net/ftldns/database/ I tried the last command in this page ("sqlite3 [...]").
Again 1 CPU got 100% and other 31 were Idle.

So, php-cgi and/or sqlite3 php extension aren't prepared to use all CPUs.

So...

The upcoming API and new web interface should help with this in some ways, especially for the long term query log due to using server-side pagination.

Let's wait for new version...

Thanks for your detailed answer.

Hello,

I have the same problem. I have a PC with 4 cores and Pihole always uses only 1 core. I searched the internet how I could fix this but without result. Pihole is updated with the last version. Does anyone have a solution for this?

1 Like