ktamas77 / firebase-php

Firebase PHP Client
791 stars 215 forks source link

Slow query #76

Open harding13 opened 6 years ago

harding13 commented 6 years ago

Hi all

i'm using firebase-php to make a query against a firebase db where i stored chat data.

the structure is a thing like this

chat
----chat_ID
------------node_ID

when i search into a chat (with one or many children) with a code like this

$firebase = new \Firebase\FirebaseLib(DEFAULT_URL, DEFAULT_TOKEN);
$value = $firebase->get('/chat/'.$chat, array('orderBy' => '"status"', 'equalTo' => '"unread"'));

the query needs almost 700ms to get a result (even if there is only one node)

I think it's too much... or not?

ova-adam commented 6 years ago

Same here, I'm reading a /records/rec_id/node_id and it takes 300-700ms, however on the firebase profiler, it shows 0ms.

ova-adam commented 6 years ago

Looks to be a CURL issue, here are some stats from when I log with curl:

time_namelookup:  0.153
  time_connect:  0.161

time_appconnect: 0.357 time_pretransfer: 0.357 time_redirect: 0.000 time_starttransfer: 0.408

    time_total:  0.408
harding13 commented 6 years ago

@ova-adam so there is nothing to do?

ova-adam commented 6 years ago

@harding13 there is, CURL requests are very slow as you can see. Is this an issue of CURL or FB at the core?

harding13 commented 6 years ago

I see it but i don't know how to solve it :)

ova-adam commented 6 years ago

Is this an issue with this library, firebase, or curl? This long lag doesn't happen if I curl a website like Google.com

If this can't be eliminated, this is a deal breaker for our project.

harding13 commented 6 years ago

I choosed Firebase because of its speed. But if i must wait 0.7 sec for every query, maybe, i must switch to another technology (or another way of using FB)

mastef commented 5 years ago

@ova-adam @harding13 Since your issue the library has been also updated so the curl handle is re-used for consecutive requests, which should reduce your connection times to the firebase server for repeat queries.

A few other things that improved connection times drastically I've mentioned here: https://github.com/ktamas77/firebase-php/issues/68#issuecomment-502921193

Related SO : https://stackoverflow.com/a/26568867/10728554