php-rql icon indicating copy to clipboard operation
php-rql copied to clipboard

Performance issues(?)

Open RoySegall opened this issue 7 years ago • 2 comments

I'm working on setting up RethinkDB as a cache layer for Drupal and I saw that when I'm querying a MySQL server the response time is 0.7 seconds and when querying RethinkDB the process takes something like 1.4 seconds.

The request is for 1,000 records:

    for ($i = 0; $i <= 1000; $i++) {
      if ($operation == 'write') {
        $cache->set('testing' . $i, time());
      }
      else {
        $cache->get('testing' . $i, time());
      }
    }

Eventually, the query is:

    $documents = $this->table
      ->getMultiple($cids, ['index' => 'cid'])
      ->run($this->connection);

And as you can see I created an index for cid. which improve the query from 5 seconds to 1.4.

Profiling the query from RethinkDB side takes about 3ms so the suspect is the Driver.

Any idea?

RoySegall avatar Oct 12 '16 12:10 RoySegall

OK, I found out what's the problem. The first is used XDEBUG and it's slow the performance of PHP but It seems that createCursorFromResponse iterate over the results and create a cursor object.

This could very cool but it's not scaleable. Why not give to improve the DX by 2 ways:

  1. Change all the private methods to protected methods so developers could override the methods.
  2. Set a flag which can give the option to decide of cursor object need to be returned or just a normal array thus give the user much more fluid workflow.

@danielmewes thoughts?

RoySegall avatar Oct 15 '16 18:10 RoySegall

@RoySegall if the full data set fits into memory, there are already two options for getting the result as an array rather than a cursor:

  1. Calling the ->toArray() method on the cursor object. This will convert the cursor into an array, but maintain the batched protocol between the client and the server. This has the advantage that less resources are used on the server, but at the cost of some additional communication and protocol overhead.
  2. (I think this is what you want): Appending a ->coerceTo("array") to the query, before the ->run. This will perform the array conversion server-side.

Can you try if option 2 gives you better performance? It will entirely cut out the cursor part.

danielmewes avatar Oct 22 '16 02:10 danielmewes