Comments (6)
Hi Nick, I just got around to trying this and it works really well.
I did some reading up and MS indicate the DocumentClient should be used in the same way as an HttpClient. i.e. One instance of it per AppDomain. That was comforting so I implemented your suggestion and massively reduced the warmup time.
In case anyone has a similar issue to mine, I did this:
var docClient = new DocumentClient(new Uri(CosmosUri), CosmosKey, new ConnectionPolicy
{
ConnectionMode = ConnectionMode.Direct,
ConnectionProtocol = Protocol.Tcp
});
var client = new CosmonautClient(docClient);
and then called each CosmosStore as:
fooCosmosStore = new CosmosStore(client, CosmosDbName);
I get the 2-3 second lag on the first init of a CosmosStore but once the client is connected the rest of them are created in < 1 second each. That's way quicker than before.
I now have one DocumentClient per service/region so that seems like a good solution.
Thanks for your help!
from cosmonaut.
Hello and thank you for your kind worlds.
Cosmonaut will do some check in the beginning to make sure you database and collection exists and if not it will create them. This takes some time on initialisation but it can’t be shared across CosmosStores.
On top of that the DocumentClient internally will make a bunch of calls to get some stuff like a pkrange cache or a location cache. This is about 8 requests and 2-3 seconds.
There is not much I can do about the internal one and thats where the performance is noticeable. I am currently investigating the idea of sharing the DocumentClient across all CosmosStores instead of having one per CosmosStore. This would get rid of this issue but I don’t know what that would mean for performance.
However if you are registering as a singleton, you can just initialise your CosmosStores on the application startup and you shouldn’t notice this initial overhead because the app wouldn’t be running yet.
Does that make sense?
from cosmonaut.
Thanks, yep that makes sense. I do warm it up at startup but with 3 regions/services it takes about a minute. That's fine for a deploy but not so good for a scale-out action on Azure App Service as it's not available for 60 seconds right when you need it. Sharing the DocumentClient sounds like it would solve my issue. If you made it possible to do that as an option I'd be happy to test it :)
Thanks for the quick reply and keep up the great work!
from cosmonaut.
There is actually a way to do that yeah. Well kind of. You would have to create a DocumentClient object with your settings, then call the OpenAsync method to do all the initial calls, then use that document client to create a CosmonautClient and then use that to initialise your CosmosStores.
This should work, give it a try and let
me know.
from cosmonaut.
Cheers! I will give that a try and let you know how it goes.
from cosmonaut.
Closing this. Feel free to reopen if you need further help.
from cosmonaut.
Related Issues (20)
- RequestRateTooLarge in AppInsights HOT 5
- how can i add attachements? HOT 1
- Continuation token does not work if first page contains all null in orderby field HOT 1
- Pagination with MAX_ITEM_COUNT -1 HOT 3
- CosmosStore.AddAsync with RequestOptions throws RuntimeBinderException when using TypeNameHandling.All HOT 4
- Cosmonaut v3 SDK
- Exception: There is no way this will ever be thrown. (What all great developers say) HOT 3
- Polymorphic Store type HOT 2
- Exceition: FindAsync returning Resource Not Found HOT 1
- v3 SDK - WithPagination with token missing? HOT 1
- Timeline for v3 HOT 5
- Problem using Cosmos Resource Tokens HOT 1
- I'm going for EF Core 3.1 for Cosmos Db mapping. Did I miss something? HOT 4
- Query execution metrics HOT 1
- Customize the CosmosEntityName property to avoid data migration HOT 1
- WithPagination - have I can repeat my query?
- Failing on unit tests when calling ToListAsync()
- [FEATURE][QUESTION] support for geospatial queries?
- Exception: The input authorization token can't serve the request.
- Error because constructor is missing for the CosmosStoreTrigger extension for azure functions
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cosmonaut.