Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Spanner] Where is NumChannels config? #1052

Closed
castaneai opened this issue May 11, 2018 · 7 comments
Closed

[Spanner] Where is NumChannels config? #1052

castaneai opened this issue May 11, 2018 · 7 comments
Assignees
Labels
api: spanner Issues related to the Spanner API. grpc type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@castaneai
Copy link

In Go client library, There is NumChannels in ClientConfig.
And the max number of sessions is determined by NumChannels.

	// Default configs for session pool.
	if config.MaxOpened == 0 {
		config.MaxOpened = uint64(config.NumChannels * 100)
	}

https://github.com/GoogleCloudPlatform/google-cloud-go/blob/master/spanner/client.go#L157

But PHP client library has this fixed to 500 by default.

    /**
     * @var array
     */
    private static $defaultConfig = [
        'maxSessions' => 500,
        ...
    ];

Where is NumChannels on PHP?
How many channels does library open by default ?

@jdpedrie jdpedrie added type: question Request for information or clarification. Not an issue. api: spanner Issues related to the Spanner API. labels May 11, 2018
@jdpedrie
Copy link
Contributor

jdpedrie commented May 11, 2018

Hi @castaneai,

When you create a Session Pool instance, you can override the values specified in $defaultConfig:

use Google\Cloud\Spanner\Session\CacheSessionPool;

$cache = \MyPsr6CacheImplementation;
$pool = new CacheSessionPool($cache, [
    'maxSessions' => 250
]);

By default, Google Cloud PHP will create enough sessions to reach the minimum session count, configured in the constructor ($config['minSessions']). By default, this is simply 1. If the number of sessions in use at any given time is higher than that minimum level, Google Cloud PHP will create additional sessions on demand up to the maxSessions limit. When those sessions are not allocated, they will wait in the pool until they are picked up by the next requester, or eventually they will be cleaned up.

If your configuration requires a minimum number of sessions higher than one, it is recommended that you call CacheSessionPool::warmup() when starting a new pool (not on every request, but when the asynchronous pool is started). This will fill the session pool to the minimum value, and if done outside of a user's request it will do so without the additional latency required for on-demand session creation.

@castaneai
Copy link
Author

@jdpedrie Thank you for your reply!

In my recognition, "Cloud Spanner Session" and "gRPC Channel" are in different layers.

Cloud Spanner documentation says the following
https://cloud.google.com/spanner/docs/sessions#create_and_size_the_session_cache

(For users working with the RPC API, we recommend having the cache store no more than 100 sessions, because 100 is the maximum number of concurrent sessions per gRPC channel.)

In case of 500 which is the default value of maxSessions, Is it correct in the configuration with 5 gRPC channels (NumChannels in Go client library) and 100 Cloud Spanner sessions?

@jdpedrie
Copy link
Contributor

@castaneai thanks for the additional information, and my apologies for misunderstanding the question. I'm working on getting a bit more information about this and will reply again as soon as I have an answer!

@jdpedrie
Copy link
Contributor

Hi @castaneai,

Thanks for your patience while I looked into this issue. At this time, it is only possible to maintain a single channel at a time within gRPC. We've opened an issue with the gRPC team to explore options to increase this limit.

I'm going to keep this issue open for further discussion and to track the feature on our side. Please let me know if you've got any questions!

@jdpedrie jdpedrie added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. grpc and removed type: question Request for information or clarification. Not an issue. labels May 17, 2018
@ZhouyihaiDing
Copy link
Contributor

Hi @castaneai ,
Can you please provide us a sample code to reproduce this issue? I am trying to solve the issue in the gRPC part and want to verify that our solution works.
Thank you for the help!

@castaneai
Copy link
Author

@ZhouyihaiDing Thank you for improving gRPC.
But this issue is not actually a problem but I just wrote a question that I had while watching APIs from other languages.

@dwsupplee
Copy link
Contributor

Thanks to some great work by @ZhouyihaiDing and @WeiranFang (via #1243) our Spanner client now has support for a pool of channels with a default max size of 10. Going to close this out now, if there's anything else we can help address here please feel free to re-open!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the Spanner API. grpc type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

4 participants