The Client Creates 17 Threads for Each PHP Process


#1

I noticed a weird behavior of PHP client, when I connect to Aerospike server, additional threads are created, for each PHP process, no matter in fpm or in cli mode.

My environment:

Intel i5-3210M CPU, 10G RAM
Ubuntu 14.04
PHP 5.6.17
PHP Aerospike client 3.4.3
Aerospike Community Server 3.6.3 (Single node)

Configured fpm to run single worker process:

vim /etc/php5/fpm/pool.d/www.conf

pm = static
pm.max_children = 1

Steps:

  1. Restarts the php-fpm service;
  2. Use htop command to see all processes, filter with fpm, now I see only 1 worker process:
  3. Open the web browser to visit a page to connect to Aerospike;
  4. Check htop screen, now I see additional 17 threads are created:

I retried many times with different pm.max_children or even in cli mode, get the same result, once Aerospike server is connected, 17 threads are created.

I don’t know if this is normal, and wonder the purpose, to create so many threads for each process.


#2

How many nodes do you have in the cluster? You should expect to see 2*N threads [ + 1], where N is the number of nodes in the cluster, per-cluster. Each client will connect to the service and info ports on each of the cluster nodes. The extra node is cluster-tending, which can be shared among the processes using aerospike.shm.use=1.

The purpose is to enable fast key-value operations, regardless of where the key is physically stored. Since there’s an equal probability that the record’s key will map to any of the nodes, the connections are established at the point the client is initialized in order to pay the setup cost up-front. After initialization there may be more threads created, depending on the load, but that’s unlikely in the PHP context, as it has a single execution thread. This may happen in HHVM, though.


#3

Thank you for your explanation.

I have only node in the cluster, so according to the formula 2*N threads [ + 1], it should be 3 threads.


I found another interesting, on our production environment.

We have 2 nodes in the production cluster, but it performs the same behavior, 17 threads for a fpm process:

Production configuration:

Ubuntu 14.04
PHP 5.6.14
PHP Aerospike client 3.4.4
Aerospike Community Server 3.7.1 (2 nodes)

Most efficient connection handling?
#4

I figured out the mystery. The client has a default thread pool size of 16. Add one more thread for cluster tending, and you have 17.

You can configure that to a lower number if you’re going against a smaller cluster.


#5

:+1: Get it! Thank you again for your explanation!