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

feat: Add multi get #53

Merged
merged 8 commits into from
May 10, 2022
Merged

feat: Add multi get #53

merged 8 commits into from
May 10, 2022

Conversation

poppoerika
Copy link
Contributor

Add MultiGetAsyc following the example of multi_get in the Python SDK.

Closes #52

Minor typo in function argument
DateTime deadline = DateTime.UtcNow.AddSeconds(this.dataClientOperationTimeoutSeconds);
try
{
_GetResponse resp = await this.grpcManager.Client().GetAsync(request, new Metadata { { "cache", cacheName } }, deadline: deadline);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With how we are currently looping through each key and then awaiting an async call here this will end up being a pretty slow call since its doing them 1 at a time. I think we will want to use async tasks and the WhenAll method for allowing us to fire off all the requests in parallel before awaiting their responses.

https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task.whenall?view=netframework-4.7.1

Copy link
Member

@eaddingtonwhite eaddingtonwhite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice this is looking good to me now! Maybe have @wandaitzuchen take pass as well get another pair 👀 on it as well.

@eaddingtonwhite
Copy link
Member

@poppoerika is test failure because of issue in alpha still?

@poppoerika
Copy link
Contributor Author

@eaddingtonwhite - It failed because of the alpha issue, but it looks like the issue has been resolved?
At least, now it's passing all the tests.


namespace MomentoSdk
{
internal sealed class ScsDataClient : IDisposable
{
private readonly DataGrpcManager grpcManager;
private readonly uint defaultTtlSeconds;
private readonly uint dataClientOperationTimeoutSeconds;
private const uint DEFAULT_DEADLINE_SECONDS = 5;
private readonly uint dataClientOperationTimeoutMilliseconds;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious why switching to milli?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We thought that more control over request timeout might be needed since we're offering a performant cache product. Also matching with the Python SDK as well as making the failure test possible to make sure multi get accept failed responses as argument.
cc @eaddingtonwhite

Comment on lines 84 to 101
{
tasks.Add(SendMultiGetAsync(cacheName, Convert(key)));
}

await Task.WhenAll(tasks);
foreach (Task<CacheMultiGetResponse> t in tasks)
{
if (t.Result.SuccessfulResponse() is not null)
{
successResponses.Add(t.Result.SuccessfulResponse());
}
if (t.Result.FailedResponse() is not null)
{
failedResponses.Add(t.Result.FailedResponse());
}
}

return new CacheMultiGetResponse(successResponses, failedResponses);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: feel like this is a bit much code repetition. would be nice to clean this up a bit. just a nit.

wandaitzuchen
wandaitzuchen previously approved these changes May 10, 2022
Copy link
Contributor

@wandaitzuchen wandaitzuchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

@poppoerika poppoerika merged commit 5eb7772 into main May 10, 2022
@poppoerika poppoerika deleted the feat/addMultiGet branch May 10, 2022 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add multi_get
4 participants