atyagi / elasticache-laravel

Elasticache Session and Cache Drivers for Laravel
MIT License
25 stars 10 forks source link

ElasticacheServiceProvider running connect and slowing page down when no memcached driver in use #13

Closed pbean closed 8 years ago

pbean commented 9 years ago

Hi Everyone,

I recently installed this project on a site I'm working on and found the strangest bug, Im unfortunately new to laravel and haven't done any real web development in well over 10 years so I seem to be running into circles finding out why this is happening. The problem is this, ever since I added this package, every environment I use my file driver on (I only use memcached [only for my session driver at that] as of right now in my Production instance, I use file for dev and homestead) has incredibly long startup times anywhere from 10-30 seconds almost for anything, ajax, page load, static content you name it. I ran my site through blackfire.io and it appears that your package is running it's connect function at register and hanging on memcached::getVersion() so every request to the site get's locked in this if you dont have a memcache driver loaded via your config. I was inspecting the laravel version but ...I went down a few levels on the driver and just got lost(it is 1:30 in the morning right now)

Is there anyway we can put in a check to see if the driver is even being used before adding servers and initiating connect?

My production site purrs like a kitten thank you very much for your plugin because it is using elasticache but....man....on my dev and homestead.....the loading times just to view a quick css change on top of the lag elixir has for gulping since im one of the few rando's with a gulp watch that errors out after any changes when using the elixir version cache buster...2 minutes wait easy on my project of staring at nothing.....just...to change...a font color, hah Im about ready to punt my computer so any help would be great!!!

Thanks, Paul

atyagi commented 9 years ago

Hey Paul,

Since this package provides functionality for session handling, by default the Service Provider will be booted up on each request and will run. If you're only using it in your production environment, make sure to only add the Service Provider to the providers array in your config/app.php file.

Hope that helps!

aligajani commented 8 years ago

@atyagi can you please give an example of what you stated earlier? I am only looking to use this for caching ,not sessions.

atyagi commented 8 years ago

Hey @aligajani - you can certainly use this for just caching and not sessions, but the service provider will be booted up on each request, not just requests that have a cache call in them. What I described above is more a reference to using different service providers between environments.

aligajani commented 8 years ago

Okay thanks. How do I just use it for caching and not sessions. Basically, I don't want it to load up on each request. Also, I am using JWT so not sure if it will make any difference at all.

On Mon, Aug 1, 2016 at 6:32 AM, Ankit Tyagi notifications@github.com wrote:

Hey @aligajani https://github.com/aligajani - you can certainly use this for just caching and not sessions, but the service provider will be booted up on each request, not just requests that have a cache call in them. What I described above is more a reference to using different service providers between environments.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/atyagi/elasticache-laravel/issues/13#issuecomment-236492933, or mute the thread https://github.com/notifications/unsubscribe-auth/ABpo2grOe4xhQ0Bhq8KOHOoemspZ_qwHks5qbYTUgaJpZM4F0oXZ .

Ali Gajani Founder at Mr. Geek www.mrgeek.me www.aligajani.com

atyagi commented 8 years ago

Sorry for the delayed response, but if you want to use it just for caching, but not sessions, then you just need to change the driver in the cache.php file, but leave the session driver the same in the session.php file.

Unfortunately, since the service provider has to register both session and cache drivers to the framework, the connection will be made on each request.

I'm open to a PR on potentially modifying the service provider to do that, but to be honest I'm not sure if that's entirely possible since the service provider has to tell the framework about the new drivers. Maybe some sort of lazy loading would be possible, but I'm not sure.

aligajani commented 8 years ago

Well, for now I'll just pull in the package and remove the loading of Session feature all together.

That'll work.

On Mon, Aug 8, 2016 at 5:23 AM, Ankit Tyagi notifications@github.com wrote:

Sorry for the delayed response, but if you want to use it just for caching, but not sessions, then you just need to change the driver in the cache.php file, but leave the session driver the same in the session.php file.

Unfortunately, since the service provider has to register both session and cache drivers to the framework, the connection will be made on each request.

I'm open to a PR on potentially modifying the service provider to do that, but to be honest I'm not sure if that's entirely possible since the service provider has to tell the framework about the new drivers. Maybe some sort of lazy loading would be possible, but I'm not sure.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/atyagi/elasticache-laravel/issues/13#issuecomment-238139152, or mute the thread https://github.com/notifications/unsubscribe-auth/ABpo2gfCC1WpsCCMByKlnbzH3IMK9hUNks5qdq83gaJpZM4F0oXZ .

Ali Gajani Founder at Mr. Geek www.mrgeek.me www.aligajani.com

atyagi commented 8 years ago

I'm going to close this issue. Please open a new one if something comes up.