Skip to content

Use elastic multiple search for network stats - #1627

Merged
stefangutica merged 2 commits into
developmentfrom
network-stats-improvements
Aug 28, 2026
Merged

Use elastic multiple search for network stats#1627
stefangutica merged 2 commits into
developmentfrom
network-stats-improvements

Conversation

@stefangutica

Copy link
Copy Markdown
Collaborator

Reasoning

  • GET /network/stats issued four separate Elastic count requests (blocks, accounts, transactions, scResults), one per count.
  • They are independent queries with no dependency between them, so _msearch can batch all four into a single HTTP request.

Proposed Changes

  • Add IndexerService.getStatsCounts(), backed by one _msearch in ElasticIndexerService, returning all four counts as StatsCounts.
  • NetworkService.getStats now makes that single call; the unused AccountService / TransactionService / SmartContractResultService dependencies were dropped.
  • Add postNdjson to EsCircuitBreakerProxy: ElasticService.post cannot set headers, and axios corrupts an ndjson body when the content type is application/json. Requests still go through the circuit breaker.
  • Pass max_concurrent_searches, otherwise _msearch runs the sub-searches less concurrently than four parallel requests would.
  • Cache the unified result under CacheInfo.StatsCounts (1s TTL) to preserve the caching the individual counts had, and keep honouring noCache.

How to test

  • GET /network/stats returns the same values as before; counts verified against the four individual _count queries on devnet (blocks, accounts, transactions, scResults all matched).
  • Elastic receives one request per second for these counts instead of 2-4 per call.
  • GET /network/stats?noCache=true bypasses the cache.
  • npm run test -- circuit.breaker.proxy passes.

@github-actions

github-actions Bot commented Aug 28, 2026

Copy link
Copy Markdown

k6 load testing comparison.
Base Commit Hash: 8733370
Target Commit Hash: 8fe1076

Metric Base Target Diff
AvgMax9095AvgMax9095AvgMax9095
Mex23.43315.8343.4255.8027.01169.9936.3441.32+15.30% 🔴-46.18% ✅-16.32% ✅-25.95% ✅
Tokens129.991708.02172.52252.9727.13351.9336.2041.42-79.13% ✅-79.40% ✅-79.02% ✅-83.63% ✅
Blocks95.66805.17155.85187.2852.0310103.5648.2159.68-45.61% ✅+1154.84% 🔴-69.06% ✅-68.13% ✅
Accounts124.22469.71212.38264.93199.301017.52336.88436.66+60.45% 🔴+116.63% 🔴+58.62% 🔴+64.82% 🔴
Nodes8567.9013666.1613666.0913666.1327.07189.6836.2641.40-99.68% ✅-98.61% ✅-99.73% ✅-99.70% ✅
Transactions210.12490.00488.94489.2464.7613983.2745.7667.44-69.18% ✅+2753.71% 🔴-90.64% ✅-86.22% ✅
Pool23.54855.4242.9055.9527.12383.1136.2441.42+15.19% 🔴-55.21% ✅-15.53% ✅-25.97% ✅
Test Run Duration60004.1060003.05

Legend: Avg - Average Response Time, Max - Maximum Response Time, 90 - 90th Percentile, 95 - 95th Percentile
All times are in milliseconds.

@stefangutica
stefangutica merged commit ba269ea into development Aug 28, 2026
6 of 7 checks passed
@stefangutica
stefangutica deleted the network-stats-improvements branch August 28, 2026 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants