Skip to content

Performance testing#12541

Open
tumbledwyer wants to merge 6 commits intodevelopfrom
performance-testing
Open

Performance testing#12541
tumbledwyer wants to merge 6 commits intodevelopfrom
performance-testing

Conversation

@tumbledwyer
Copy link
Copy Markdown
Contributor

@tumbledwyer tumbledwyer commented May 6, 2026

Description

A number of improvements to increase the performance of OpenCRVS events service:

Remove the wait_for when using the API

Every request waits for elasticsearch to index the changes before returning.
This is on an interval of once per second.
This is useful from the UI so that refresh only happens once elasticsearch is updated.
From a performance testing perspective, it makes it impossible to get real number.

Changed to wait_for on request from the client, API requests immediately return.

Improved Zod schema parsing

Code previously parsed all Zod schemas and then checked how many it parsed and then selected highest priority if the number of parse matches was greater than 1.

Changed to order schemas by priority and then parse until it found a match. Logic is equivalent but dramatically reduces amount of processing on every request.

Cache Admin Structure

Admin structure is requested on every write operation, multiple times.

Added a cache since this almost never changes. This was the biggest saving in the tests.

Remove repeat calls to getEventById

Multiple calls to getEventById in a single request. The event exists in ctx.event so does not need to be refetched.

Used ctx.event where possible and passed event as a parameter otherwise. There is still some possible further optimisation here.

Checklist

  • I have linked the correct Github issue under "Development"
  • I have tested the changes locally, and written appropriate tests
  • I have tested beyond the happy path (e.g. edge cases, failure paths)
  • I have updated the changelog with this change (if applicable)
  • I have updated the GitHub issue status accordingly

@tumbledwyer tumbledwyer force-pushed the performance-testing branch from c29c74d to d9d584a Compare May 6, 2026 12:08
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

Oops! Looks like you forgot to update the changelog. When updating CHANGELOG.md, please consider the following:

  • Changelog is read by country implementors who might not always be familiar with all technical details of OpenCRVS. Keep language high-level, user friendly and avoid technical references to internals.
  • Answer "What's new?", "Why was the change made?" and "Why should I care?" for each change.
  • If it's a breaking change, include a migration guide answering "What do I need to do to upgrade?".

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

ℹ️ Coverage metrics explained:
Statements — Executed code statements (basic logic lines)
Branches — Tested decision paths (if/else, switch, ternaries)
Functions — Functions invoked during tests
Lines — Source lines executed

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

📊 commons test coverage

Statements: 75.5%
Branches:   39.93%
Functions:  56.78%
Lines:      75.09%
Updated at: Wed, 06 May 2026 12:18:09 GMT

@ocrvs-bot
Copy link
Copy Markdown
Contributor

Your environment is deployed to https://performance-testing.e2e-k8s.opencrvs.dev

Copy link
Copy Markdown
Contributor

@Zangetsu101 Zangetsu101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work. Just wondering would it be easier to maintain a events cache tied to the request's lifecycle instead of passing it around?

export async function getLeafLevelAdministrativeAreaIds() {
const db = getClient()
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let leafLevelAdministrativeAreaIdsCache: Promise<any[]> | null = null
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UUID or string?

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