I have a PHP 7.2 script which uses MySQLi to connect to a MariaDB database. On an older host running CentOS 7 and MariabDB 10.2.44, the script running locally completes in about 10 seconds. This is what the Mariadb general log shows:
85338332 Connect myuser@localhost as anonymous on myserver
85338332 Quit
85338333 Connect myuser@localhost as anonymous on myserver
85338333 Quit
85338334 Connect myuser@localhost as anonymous on myserver
85338334 Quit
85338330 Query INSERT INTO auditlog(name, userid, ipaddress, useragent, notes) values ("recordtype", "31", "10.20.30.123", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36", "myfile.csv")
85338330 Quit
85338335 Connect myuser@localhost as anonymous on myserver
85338336 Connect myuser@localhost as anonymous on myserver
85338336 Quit
85338337 Connect myuser@localhost as anonymous on myserver
85338337 Quit
85338335 Query SELECT COUNT(id) as id FROM case_file
WHERE code = '18676'
AND modelcode = 'PW786756'
85338338 Connect myuser@localhost as anonymous on myserver
85338338 Quit
85338339 Connect myuser@localhost as anonymous on myserver
85338339 Quit
... and so on.
I have migrated this script to a dedicated Rocky 8 Linux host which connects to MariabDB 10.5.22 on a separate host within the same network. Ping times between hosts average 0.5 ms. However, the same script takes over 80 seconds to complete, and on occasions times out. This is what the Mariadb general log shows:
6124914 Connect [email protected] on myserver using TCP/IP
6124914 Quit
6124915 Connect [email protected] on myserver using TCP/IP
6124915 Quit
6124916 Connect [email protected] on myserver using TCP/IP
6124916 Quit
6124912 Query INSERT INTO auditlog(name, userid, ipaddress, useragent, notes) values ("recordtype", "31", "10.20.30.123", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36", "myfile.csv")
6124912 Quit
6124917 Connect [email protected] on myserver using TCP/IP
6124918 Connect [email protected] on myserver using TCP/IP
6124918 Quit
6124919 Connect [email protected] on myserver using TCP/IP
6124919 Quit
6124917 Query SELECT COUNT(id) as id FROM case_file
WHERE code = '18676'
AND modelcode = 'PW786756'
6124920 Connect [email protected] on myserver using TCP/IP
6124920 Quit
6124921 Connect [email protected] on myserver using TCP/IP
6124921 Quit
Also, I noticed on the new host where the PHP script is running, the port/sockets in use increases significantly from approximately 60 to over 22000 by using a command such as this:
netstat -nt | grep -i '10.50.30.40:3306' | wc -l
I have increased the port range on the new host:
# sysctl net.ipv4.ip_local_port_range
net.ipv4.ip_local_port_range = 15000 60999
The queries themselves appear to be running quickly as they don't appear in the slow query log configured to capture any queries that take longer than 1 second (long_query_time = 1.00000).
Any ideas why the script is taking longer to run?