php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76565 Very slow DB queries
Submitted: 2018-07-02 19:06 UTC Modified: 2023-01-10 17:13 UTC
Votes:8
Avg. Score:3.6 ± 1.3
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:0 (0.0%)
From: gilperon at gmail dot com Assigned:
Status: Open Package: MySQLi related
PHP Version: 7.2.7 OS: CENTOS 7
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: gilperon at gmail dot com
New email:
PHP Version: OS:

 

 [2018-07-02 19:06 UTC] gilperon at gmail dot com
Description:
------------
PHP 7.2 is very fast, amazingly fast. Doing very simple benchmarks (like looping thousands of times and doing some basic arithmetics) demonstrates that PHP 7.2 is easily 3x faster than PHP 5.4.16 (which is the default PHP version that comes enabled to be installed on Centos 7 using the "yum").

BUT for some strange reason doing DB queries is AT LEAST 2X slower - at least.

I booted 2 CENTOS (version 7.1) servers - identical. Then on one I installed PHP 5.4.16 and in the other I installed PHP 7.2.7 (both were running the latest version of MariaDB).

Then I created a simple database and executed the benchmarking in the TEST SCRIPT section.

I executed this code at least 5 times on each server, allowing some delay between tests. They were very clear:

PHP 7.2 took about 4.5 seconds to run PHP 5.4.16 took about 1.1 seconds to run

So what? Is there something with PHP 7.2 that I am not aware that I should be taking into account when querying db?

Test script:
---------------
<?php

include("connect.php");

$microtime = microtime(true);

for ($i=0;$i<100;$i++) {

    $query = "SELECT * FROM table WHERE id = 'xxx'";
    $result = mysqli_query($connection,$query);
    $data = mysqli_fetch_array($result);

}

echo microtime(true) - $microtime;

?>

Expected result:
----------------
It should run AT LEAST at the same speed as PHP 5.4.16

Actual result:
--------------
It runs at least twice or 3 times as slow.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-07-03 04:47 UTC] remi@php.net
I cannot reproduce such difference.

You seems to have some very big table / row, as I have to increase the loop to 10000 to have 1/2 second, on a small RHEL-7.5 VM

    PHP Version 5.4.16 en 0.55 (using php-mysql and libmysqlclient)
    PHP Version 5.4.16 en 0.65 (using php-mysqlnd)
    PHP Version 5.5.38 en 0.66
    PHP Version 5.6.36 en 0.65
    PHP Version 7.0.30 en 0,67
    PHP Version 7.1.19 en 0,67
    PHP Version 7.2.7 en 0,69
    PHP Version 7.3.0alpha2 en 0.55
 [2018-07-03 09:09 UTC] celestinoxp at hotmail dot com
I think you should show more details, like the mysql configuration file. In addition, the details of your system are also essential, cpu, ram.
 [2018-07-03 11:44 UTC] cmb@php.net
Is this a duplicate of bug #76442?
 [2018-07-03 13:53 UTC] gilperon at gmail dot com
cmb@php.net I think my problem is similar to the one you referenced to. That other guys looks having the same problem as me BUT I am running a CENTOS 7 server (intead of linux). My Centos is 2GB RAM and 2vCPU (AMD EPYC).
 [2018-07-03 23:06 UTC] yohgaki@php.net
You cannot get reliable results from virtual environment.
In general, benchmarks should be taken by using dedicated machine.

At least, you should execute benchmark on the same virtual machine. i.e. Install php 5.4 and 7.2 on the same machine and take benchmark. 
Make sure you use the same disk/database also, and see what you get.
 [2018-07-03 23:22 UTC] gilperon at gmail dot com
I can run the test using different php version on the same machine if you want. BUT I dont know how to install php 5.4.16 on my centos and later remove it to install 7.2. I tried many methods online and I couldnt find an updated one that works. Any suggestion/link where I can try that?
 [2023-01-10 17:13 UTC] dharman@php.net
-Package: MySQL related +Package: MySQLi related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Oct 12 00:01:40 2024 UTC