I'm using @azure/cosmos v3.17.2 for node in an Azure function app to query Cosmos DB (for NoSQL) and return all items in a container. There are only ~200 items in the container currently, but the network tab of developer tools shows that the API call is taking 5.74s to complete, which seems ridiculous. You can see in the following image that 4.95s is waiting for response from server.
Here is my function code to query the database:
const CosmosClient = require('@azure/cosmos').CosmosClient;
const config = require('../config/config');
const { endpoint, key, databaseId } = config;
const client = new CosmosClient({ endpoint, key });
const database = client.database(databaseId);
module.exports = async function (context, req) {
const containerId = req.query.containerId;
const container = database.container(containerId);
const querySpec = {
query: 'SELECT * from c'
}
const { resources: items } = await container.items
.query(querySpec)
.fetchAll()
context.res = {
body: items
}
}
Is there a way to speed this up? The partition key is currently id, would changing this make it faster? Another thought is that the response times could possibly be from cold starts, but how can I prevent that in a function app that's already established? I know that a dedicated app service plan helps minimize cold starts, but it doesn't seem possible to change consumption to dedicated after it's already been created. Also of note, I already have WEBSITE_RUN_FROM_PACKAGE set to 0 in configurations and I have removed all unnecessary npm packages
Any help would be appreciated!