What's the preferred way to manage Cloud Storage and Datastore connection objects in ASP.NET?
See original GitHub issueI’ve been using the Datastore and the Cloud Storage in an ASP.NET (Core) application, and I’m wondering what’s the preferred way to manage DatastoreDb
and StorageClient
instances.
Currently I’m creating a new instance on every request. Is there any more sophisticated support in the library to manage the connection objects, for example some kind of pool?
Thanks!
(Is this the proper place to ask questions like this, or should I rather post it to SO?)
Issue Analytics
- State:
- Created 7 years ago
- Comments:17
Top Results From Across the Web
ASP.NET Core Best Practices
Minimize large object allocations The . NET Core garbage collector manages allocation and release of memory automatically in ASP.NET Core apps. ...
Read more >Best Practices | Cloud Datastore Documentation
You can use the best practices listed here as a quick reference of what to keep in mind when building an application that...
Read more >Working with Google Cloud Storage for ASP.NET 6 ... - YouTube
In this detailed video, we will learn how to work with Google Cloud Storage for ASP. NET 6 Web applications. This is the...
Read more >Object Storage: An Introduction
Cloud -based object storage is an ideal solution for storing and managing high volumes of static or unstructured data reliably, efficiently and affordably....
Read more >Best Practices in Using the DbContext in EF Core
Managing transactions with the database (including setting up new ones, rolling back existing ones, or even canceling them); Change tracking ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@philipri: Right - that definitely explains it, as if you were constructing a new channel on each request, that would mean a new connection.
What you’re doing is indeed fine. In production I’d expect you to be able to use
DatastoreDb.Create()
specifying just the namespace on each request - as that would use the default app credentials, it could keep a single channel open for all requests. That difference between local testing and production may be harder than just keeping a singleton client in both cases though. So long as there’s nothing I don’t understand, I think we’re fine 😃As an aside, if you have any usability feedback on the
DatastoreDb
API, now would be an ideal time to give it while the surface is still somewhat malleable.@philipri: When did you try this, out of interest? For Datastore and other gRPC-based APIs, “fairly recent” versions of the package will all share a common
Channel
if you’re using default application credentials. You definitely shouldn’t be seeing that issue.When you say the tests were “on the local store” - if that means you were creating a new channel to the local emulator each time, that would explain it. You could keep just the channel as a singleton and reconstruct the rest… but basically if you need a new connection on each request, that will be slow. You could also use the
ChannelPool
class in GAX to avoid having to create a newChannel
each time. (That’s slightly cleaner than keeping a static reference to the channel, although I admit there’s not a lot in it.)