kibana/dev_docs/key_concepts/performance/server_side.mdx
Clint Andrew Hall 37251b0925
[docs] Plugin optimization, case studies (#192285)
## Summary

As titled. This PR outlines several use cases around plugin optimization
that can be helpful to engineers. This PR is part of a series, but
divided to make review easier.

It also reworks the navigation a bit to make the optimization section a
bit more clear.
2024-09-10 14:28:18 -04:00

18 lines
No EOL
1.4 KiB
Text

---
id: kibDevPerformanceServer
slug: /kibana-dev-docs/key-concepts/performance/server
title: Server performance
description: Performance tips for plugin server code.
date: 2021-12-03
tags: ['kibana', 'onboarding', 'dev', 'performance']
---
## Don't block the event loop
[Node.js is single threaded](https://nodejs.dev/learn/introduction-to-nodejs) which means a single CPU-intensive server-side, synchronous operation will block any other functionality waiting to execute on the Kibana server. The affects background tasks, like alerts, and search sessions, as well as search requests and page loads.
**When writing code that will run on the server, [don't block the event loop](https://nodejs.org/en/docs/guides/dont-block-the-event-loop/)**. Instead consider:
- Writing async code. For example, leverage [setImmediate](https://nodejs.dev/learn/understanding-setimmediate) inside for loops.
- Executing logic on the client instead. This may not be a good option if you require a lot of data going back and forth between the server and the client, as that can also slow down the user's experience, especially over slower bandwidth internet connections.
- Worker threads are also an option if the code doesn't rely on stateful Kibana services. If you are interested in using worker threads, please reach out to a tech-lead before doing so. We will likely want to implement a worker threads pool to ensure worker threads cooperate appropriately.