Multithreading in KDB.AI
Multithreading is a powerful technique used to improve the performance of applications. In KDB.AI, the THREADS
environment variable plays a crucial role in configuring and managing multithreading.
What is a worker?
A worker in KDB.AI is a process that performs tasks such as executing queries or handling data operations. Each worker can utilize multiple threads to perform its tasks more efficiently.
What is a multithreaded operation?
A multithreaded operation is one that can be divided into smaller tasks, which are then executed simultaneously across multiple threads. This parallel execution can significantly speed up processing times, especially for large datasets or complex computations.
Setting the threads variable
The THREADS
environment variable determines the number of threads each worker uses during multithreaded operations. This makes the configuration process easier and more straightforward by using a single option.
Syntax: THREADS=<number_of_threads>
Example usage. In the server setup, you can specify the number of threads like below. By default, we recommend setting THREADS
to the number of CPU cores available on the machine running KDB.AI Server.
# On the `docker run` command:
-e THREADS="8" \
Benefits of using threads
- Improved Performance: Setting the
THREADS
variable correctly can lead to significant performance improvements in multithreaded applications. - Flexibility: You can easily adjust the number of threads to match your server's resources and workload requirements.
Use cases: qHNSW insert, qFlat/qHNSW searches across partitions, and TSS search across splayed and partitioned tables.
Next steps
Now that you're familiar with multithreading, you can improve the performance of the following actions:
- qHNSW insert.
- TSS search across splayed and partitioned tables.
- qFlat/qHNSW searches across partitions.