Streaming Engine to 5k+ Users (6) - Micro-optimization
· 2 min read
Test Goal
There is a type conversion issue that may affect the performance. Let's fix it and observe whether the performance is improved or not.
Conclusion
I fixed the type conversion issue. The P99 latency is reduced from 700ms to 450ms roughly and CPU usage is reduced a bit from from 0.8 to 0.5 roughly.
If you are interested in the testing process, please continue reading.
Optimization
message MarketPrice {
string ticker = 1; // "TSLA"
TradePrice trade = 2;
PriceChange price_change = 3;
- string timestamp = 4;
+ int64 timestamp = 4;
}
now := time.Now().UnixMilli()
for _, result := range stock.Results {
- if sourceTs, err := strconv.ParseInt(result.Timestamp, 10, 64); err == nil {
- latency := float64(now - result.Timestamp)
- }
+ latency := float64(now - result.Timestamp)
}
Result
CPU & Memory
CPU usage is reduced a bit from from 0.8 to 0.5 roughly (Yellow line).

Streaming Latency
P99 latency is reduced from 700ms to 450ms roughly (Green line).

I am alomst done with the load test. There is just one last piece of the puzzle to fix that is so called Long-tail resource leak. I will cover it in the next article.
