I wanted to call Azure Cosmos in Task.Run for 200 threads , I have configured my RU to 5000 , So just wanted to know How, Azure Cosmos Process 200 request together .. does it maintain queue to process or it will process all request together ?
I wanted to call Azure Cosmos in Task.Run for 200 threads , I have configured my RU to 5000 , So just wanted to know How, Azure Cosmos Process 200 request together .. does it maintain queue to process or it will process all request together ?
Hi @SachinAgarwal-2663, welcome to Microsoft Q&A forum.
It is advised to increase the number of threads/tasks to have better performance while using sdks. Creating number of threads will allow parallel execution of these requests and would in turn take lesser time to process multiple requests. However, we need to understand that if we create multiple requests and our RUs allocation does not meet the demand then we could see the throttling of request at the same time. Also how many threads we create will also depend on core configuration of our machine.
I would also suggest you to read below article for more details on the same:
Performance tips for Azure Cosmos DB
If answer helps, please mark it 'Accept Answer'
Thanks For your answer, but I wanted to understand, How Cosmos will process request because I have seen instances in my code If I am trying to call _container.ReadItemStreamAsync from Cosmos and there are 200 threads which is calling the same read method , so for one of the request if response is delayed then other request will also be delayed .
Example if first thread took 2 sec , second will take 2+2 , third wil also take 2+2+2 like that .. Any suggestion ?
Thanks for replying back.
Actually creating multiple threads does not guarantee that all the threads will be fired at the same time or the lagging time between threads. It depends on system's hardware how many threads will be executed simultaneously or with time interval based on CPU cores. In your example, if you are using multiple cores processor, ReadItemStreamAsync method will be fired simultaneously for fixed number of threads, so creating 200 threads would not mean all will be fired at the same time but could be in batches (example 4 threads). However, Azure Cosmos Engine will be able to process whatever threads(requests) are received based on thread execution
Also to mention if we spawn more number of threads in machines with less cores, it could in turn cause more performance issues. So we need to be diligent when we use threads.
Please let me know if it makes sense.
This is really make sense to me , I would like to create some sample application with proper stats of CPU and configuration and will share code here so that we can talk more in practical way and can explain the issues which I am facing because of threads. @AnuragSharma-MSFT Thanks for ur input.. I will post sample soon.
5 people are following this question.