framework icon indicating copy to clipboard operation
framework copied to clipboard

Auth::check() performance

Open andy3rdworld opened this issue 13 years ago • 6 comments

In testing I use the following route via a synchronous jquery ajax call. When a user is not logged in, Auth::check() returns in approx. 60-80ms. When a user is logged in, the call returns in approx. 800-900ms. My dev web server is local.

Route::get('user/loggedin', function() { return Response::json(array('loggedin' => Auth::check())); });

Is this expected performance (order of magnitude slower) for logged in user calling Auth::check()? I've tried several session drivers including Redis and all experience same performance.

andy3rdworld avatar Aug 19 '13 20:08 andy3rdworld

No that is not expected as the same code is run whether a user is logged in or not. I would check your local settings etc. 900ms would be very noticable during development. I have never noticed anything like that.

taylorotwell avatar Aug 20 '13 01:08 taylorotwell

Try another session driver instead of native and see if you get better response.

Sent from my iPhone

On 20/08/2013, at 03:44, Taylor Otwell [email protected] wrote:

No that is not expected as the same code is run whether a user is logged in or not. I would check your local settings etc. 900ms would be very noticable during development. I have never noticed anything like that.

— Reply to this email directly or view it on GitHub.

ipalaus avatar Aug 20 '13 03:08 ipalaus

From what @taylorotwell said, same code is running in

// inside vendor\laravel\framework\src\illuminate\auth\guard.php

public function check() { $time_start = microtime(true); ! is_null($this->user()); $time_end = microtime(true); $time = $time_end - $time_start; var_dump($this->user()); die($time); return ! is_null($this->user()); }

Running at about 700-900ms for $this->user (@ipalaus, as I mentioned using both Redis session driver and native) now reproduced on two machines (Linux box and Windows). I disabled Xdebug and anything else I could think of with performance implications. If this is just me, so be it, but still seems strange.

Something interesting...for routes called inside

Route::group(array('before' => 'auth'), function() {...}

the time printed is about is 1/10000 second for user that is logged in, but when this is run (same user still logged in)

Route::get('user/loggedin', function() { /$time_start = microtime(true); Auth::check(); $time_end = microtime(true); $time = $time_end - $time_start; die($time);/ return Response::json(array('loggedin' => Auth::check())); });

I still get 700-900ms on line is_null($this->user).

andy3rdworld avatar Aug 20 '13 22:08 andy3rdworld

Not sure if it's related or not, but most of the time changing the db host from localhost to 127.0.0.1 fixes issues like this, mainly on windows.

brunogaspar avatar Aug 20 '13 23:08 brunogaspar

Hello,

I struggled to make everything fast in my app, using for example redis (phpredis by the way, predis was too slow) but the auth::check() kind of slows it down.. I already set my database host to 127.0.0.1, removed xdebug but I still get execution time between 30-150ms with mysql as database (only on the first call). 0.10308814048767 <- first auth::check() then 9.0122222900391E-5 6.1988830566406E-5 6.0081481933594E-5 ...

Do you think it is possible to speed things up or it will be the fastest mysql can do ?

Thank you in advance.

trompx avatar Jul 29 '14 05:07 trompx

Entirely depends on your machine really.

On Jul 29, 2014, at 12:08 AM, trompx [email protected] wrote:

Hello,

I struggled to make everything fast in my app, using for example redis (phpredis by the way, predis was too slow) but the auth::check() kind of slows it down.. I already set my database host to 127.0.0.1, removed xdebug but I still get execution time between 30-150ms with mysql as database (only on the first call). 0.10308814048767 <- first auth::check() then 9.0122222900391E-5 6.1988830566406E-5 6.0081481933594E-5 ...

Do you think it is possible to speed things up or it will be the fastest mysql can do ?

Thank you in advance.

— Reply to this email directly or view it on GitHub.

taylorotwell avatar Jul 29 '14 14:07 taylorotwell