M
M
moem2017-07-11 11:55:24
PHP
moem, 2017-07-11 11:55:24

Are multiple parallel queries faster than a single serial one?

Hello.
Given : web application. On the client (js, jquery), Ajax requests of the form

$.ajax({
  url: "some.php",
  data: { whatyouwants: "smth1,smth2,smth3" }
})

On the server, the some.php script processes the request and generates sequential sql queries to the firebird database through one permanent PDO connection. The response from the database is converted by the same some.php into json of the form {smth1:[...], smth2:[...], smth3:[...]}and returned to the client. The database structure cannot be changed.
Problem : slow execution.
Attempt to solve : instead of one Ajax request, send three types:
$.ajax({
  url: "some.php",
  data: { whatyouwants: "smthN" }
})

Result : fiasco. For example: one Ajax request took 30 seconds (on the server: smth1 - 5 seconds, smth2 - 10 seconds, smth3 - 15 seconds, connection and transmission time is negligible). I thought that three requests together were completed in 15 seconds (for the longest request to the database). It wasn't here. With three parallel requests: smth1 - 15sec, smth2 - 25sec, smth3 - the same 30sec.
At some stage, parallel requests are also queued. If at the same time similar requests are submitted from another client, then the waiting time is even longer.
It turns out that one serial request, that several parallel ones, have a comparable duration.
Questions :
Is there a rational grain in query parallelization?
Why is there no speed boost?
Are there any apache, php, firebird settings that allow you to get a speed gain when paralleling requests?
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Melkij, 2017-07-11
@melkij

Is there a rational grain in query parallelization?

Yes, if the threads do not fight for the same resources. For example, they go to physically different database clusters.
Either you incorrectly described the observed result, or parallel execution is 2 times slower and further deteriorates with a competitive load.
Easy. But it does not look like your observed picture, your work execution time has increased several times.
So the processes fought for resources and very much interfered with each other.
which confirms the diagnosis. There are no resources for parallel execution.
Since the question affects the subd and you do not name what is happening there - the most obvious - you rested on the disks. Maybe even mechanical discs. Adding new io tasks to disks is expected and slows down the rest of the io very much.

I
Ivan, 2017-07-11
@IvanCher

Parallelization makes sense, of course. It just needs to be done at all levels. Apache has not been used for several years, so I can’t say anything here, but judging by the symptoms described, your DB is the plug.
I didn’t work specifically with firebird, but for sure it can be parallelized through replication.
Those. now you have 3 php scripts making queries to the database. The database processes requests synchronously, so there is no speed gain. You can either look in the database settings for asynchronous query processing, but it is unlikely that there is such a thing, or replicate the database as a master slave and request data from different left-servers of the database, then there will be an increase in speed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question