Skip to content

[Spanner] GCE metadata probe adding unnecessary delay when instantiating client #9316

Description

@taka-oyama

When instantiating SpannerClient on google/cloud-spanner-php v2.10.0, there is a 1.5s delay when running against the emulator.

It seems like the constructor is calling $this->configureMetrics() -> $this->getLocation() -> GCECredentials::onGce(), and this method probes http://169.254.169.254 up to 3 times with a 0.5s timeout each.
In an emulator, this endpoint doesn't exist and will cause the code to timeout, hence the 1.5s delay.

Can the following code be moved up to the top of the method so that the code doesn't have to call getLocation when enableBuiltInMetrics is set to false (the default option)?

if (!$this->pluck('enableBuiltInMetrics', $options, false)) {
return;
}

If this is fixed, I think we can expect a boost in performance for non-emulator environment as well.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions