Perf: Handle small requests more efficiently
- Dominant language
- C#
- Stars
- 1.2k
- Forks
- 378
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 6
Description
## Expected Behavior
If it was possible, to reduce the time of the method `GetBulkStateAsync` lower than 10 ms.
## Actual Behavior
The current operation takes about `64 ms` to read four keys.
## Steps to Reproduce the Problem
### Scenario configuration
- MODE
- self-hosted
- STATE STORE
- MongoDB
- DAPR INFO
- CLI version: 1.13.0
- Runtime version: 1.13.4
- SYS INFO
- OS: Windows 10 IoT 21H2
### Description
In my scenario, I have profiled the code using the `MiniProfiler.NET` package.
```csharp
IReadOnlyList multipleStateResult;
using (profiler.Step("Bulk op"))
{
multipleStateResult = await daprClient.GetBulkStateAsync(_daprStoreName, keys, parallelism: 2);
}
```
And one of the tests have delivered these results:
```bash
== APP == === PROFILING RESULTS ===
== APP ==
== APP == MYPC at 10/21/2024 6:58:21 AM
== APP == My Profiler Name 0ms
== APP == >> Main Work 98.84ms
== APP == >>>> Load state 66.67ms
== APP == >>>>>> Bulk op 66.1ms
== APP == >>>> Load dict 7.87ms
```
In this code we can conclude that:
- the time spent to my library and come back is very fast (0,57 ms aprox),
- the bulk operation is taking the most time.
I have done some tests using PowerShell calling to the State API and the results are much better (`Duration: 00:00:00.0040811 ms`).
```powershell
$uri = "http://localhost:10001/v1.0/state/state.mongodb/bulk"
$headers = @{
"Content-Type" = "application/json"
}
$body = @{
keys = @("key1", "key2", "key3", "key4")
parallelism = 20 # it is not relevant
} | ConvertTo-Json
# Capture the start time
$startTime = Get-Date
# Invoke the REST method
$response = Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $body
# Capture the end time
$endTime = Get-Date
# Calculate the duration
$durationMs = ($endTime - $startTime).TotalMilliseconds
# Output the response and duration
$response
"Duration: $duration ms"
```
## Release Note
RELEASE NOTE: **IMPROVEMENT** Better performance in the `GetBulkStateAsync` operation.
Contributor guide
Assessment
This issue has not been assessed yet.