Code Monkey home page Code Monkey logo

Comments (14)

constantijn avatar constantijn commented on May 18, 2024 3

Looks like it works, thank you very much :)

from laravel-firebase.

jeromegamez avatar jeromegamez commented on May 18, 2024 3

I'm glad, thanks for the feedback! šŸŒŗ

from laravel-firebase.

jeromegamez avatar jeromegamez commented on May 18, 2024 2

Thanks for testing it out! I think the ā€”no-dev issue could be resolved by changing the dependency to dev-discovery as 4.41.1 or by changing the minimum stability - but thatā€˜s not the point, especially if itā€˜s back at being slow.

Iā€˜ll start working on a better, more permanent solution and let you know once I have something ready. Thanks for your help and your patience!

from laravel-firebase.

jeromegamez avatar jeromegamez commented on May 18, 2024

That's an interesting problem! šŸ¤”

Are you using a Service Account JSON file locally and on GAE/GCR? If so, please try leaving the FIREBASE_CREDENTIALS environment variable empty on the Google Infrastructure - this should force the SDK to use auto-discovery and discover the GAE/GCR environment, which should save some of the expensive roundtrips via external internet connections.

I hope this helps!

from laravel-firebase.

martijnvdgrift avatar martijnvdgrift commented on May 18, 2024

Hey, thanks for the quick reaction. On local dev, I'm exposing GOOGLE_APPLICATION_CREDENTIALS as Environment variable. On GAE/GCR, I'm not setting any env vars.

from laravel-firebase.

jeromegamez avatar jeromegamez commented on May 18, 2024

Darn... I was hoping it would be as easy as that. For the moment I have no other ideas, but I will try it out tomorrow on GAE/GCR as well, if I can at least reproduce the issue, I can hopefully also figure out why this is happening. šŸ¤ž

from laravel-firebase.

constantijn avatar constantijn commented on May 18, 2024

Did some digging and i found a fix.
If i open up this file:
https://github.com/kreait/gcp-metadata-php/blob/master/src/GcpMetadata.php

and replace the constructor with:

public function __construct()
{
    $this->client = new \GuzzleHttp\Client();
}

Instead of the auto injected guzzle client then performance returns to normal. 28 seconds down to 200 milliseconds.

As for WHY this is a problem i have no idea, but this does make the problem go away.

Is there anything I can to do help to get this fixed in an official release so I don't have to monkeypatch my php code? :)

Edit:
I should probably add that we found that calls to the GCP meta data service were taking just under 5 seconds each before this fix, and after this they're back down to 2-3 milliseconds each.

from laravel-firebase.

jeromegamez avatar jeromegamez commented on May 18, 2024

You already did! Thank you for digging into it and finding a solution!

As you're currently already monkeypatching šŸ˜…, could you please try modifying the Factory in https://github.com/kreait/firebase-php/blob/master/src/Firebase/Factory.php#L418

from

} elseif ((new GcpMetadata())->isAvailable()) {

to

} elseif ((new GcpMetadata(new Client()))->isAvailable()) {

and see if this yields the same improvements? If so, I'll release a patch release today and look for a more sustainable solution after that.


Some background: I initially planned to rely on Google's packages as less as possible and to make the SDK HTTP-Client-independent (as it's currently tied to Guzzle). Unfortunately, I never came around really doing it, and so, the SDK is currently in this weird state that I'm duplicating some of the functionality that google/auth already provides. I'm not happy with that at all, but I think now could be the time to finally embrace Guzzle and the google/auth package, at least for the 4.x releases šŸ˜…

from laravel-firebase.

constantijn avatar constantijn commented on May 18, 2024

Oh, i came across that part of the code in my bug hunting ;)

That won't (completely) work because a few lines above that we call:

        $serviceAccount = $this->getServiceAccount();

That one ends up going into new Discovery\OnGoogleCloudPlatform(), which has the same metadata problem.

from laravel-firebase.

jeromegamez avatar jeromegamez commented on May 18, 2024

Ah, of course! šŸ¤¦ā€ā™‚

Could you please add/replace

"kreait/firebase-php": "dev-discovery"

to your project's composer.json to see if this helps? It's not pretty, but if it works, I would consider it good enough ^^

from laravel-firebase.

constantijn avatar constantijn commented on May 18, 2024

Ok, that causes issues:

  1. The application is back to being slow

and 2)

If i run composer install it works just fine but if i run composer install --no-interaction --no-dev it crashes with:

(1/1)Ā ErrorClass 'Kreait\Laravel\Firebase\ServiceProvider' not found

inĀ Application.phpĀ line 196
atĀ Application->register('Kreait\Laravel\Firebase\ServiceProvider')inĀ app.phpĀ line 82

from laravel-firebase.

constantijn avatar constantijn commented on May 18, 2024

Thanks for the replies so far, and looking forward to being able to rip this ugly monkey patch out of my codebase ;)

from laravel-firebase.

jeromegamez avatar jeromegamez commented on May 18, 2024

I just released a new version of kreait/gcp-metadata which should be available on Packagist by now as well.

Could you please do a composer update or add "kreait/gcp-metadata": "^1.1" to your composer.json - I hope this will resolve the issue, it's basically the same thing you already did šŸ˜…

from laravel-firebase.

constantijn avatar constantijn commented on May 18, 2024

Seems to work :)
Going to do some more testing but I ripped out my monkey patch and the response times on my rest calls are in the 100-200ms range where i expect them to be :)

from laravel-firebase.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.