# Optimize Analysis Performance with Parallel Processing

Media Server can use multiple threads to perform some analysis tasks on video. (If your source media is a single image or document, Media Server always uses one thread for each analysis task).

Using multiple threads allows Media Server to process multiple video frames simultaneously. You might want to use multiple threads for the following reasons:

- Some analysis operations are resource-intensive and cannot process video frames as quickly as they are ingested. To process a video in real time, Media Server might need to skip frames. Allowing Media Server to use more than one thread means that it can process more frames and this can increase accuracy.
- If you have configured Media Server to process a video file without skipping frames, allowing Media Server to use more threads means that the media is processed in less time.

Media Server can use multiple threads for performing:

- face detection.
- face recognition.
- face demographics analysis.
- face expression analysis.
- clothing analysis.
- optical character recognition.
- object class recognition.
- object recognition.
- number plate recognition.
- image classification.

To specify the number of threads that an analysis task can use, set the `NumParallel` configuration parameter in the task section of your configuration. For example:

    [FaceDetect]
    Type=FaceDetect
    Database=Faces
    NumParallel=2

    [NumberPlate]
    Type=NumberPlate
    Location=UK
    NumParallel=2

NOTE: If you have installed Media Server with GPU support and are configuring a task that can use the GPU, set `NumParallel=1` and use the configuration parameter `GPUNumParallel` to specify the number of video frames to process concurrently on the GPU. For more information, see Optimize Analysis Performance with a GPU.

It is important to consider the total number of threads that Media Server will use. For example, a configuration for monitoring a television broadcast might include the following tasks:

- Face detection, with `NumParallel=2` (so face detection will use two threads).
- Face recognition to recognize known faces (one thread).
- Object recognition to detect corporate logos, with `NumParallel=2` (two threads).
- Speech-to-text (one thread)
- Optical character recognition with `NumParallel=1` (one thread).
- An encoding task to write the video to disk or a rolling buffer (one thread).

This demonstrates that a single `process` action can easily consume many threads (at least eight in the previous example). If you have configured Media Server to run multiple process actions simultaneously, then the total number of threads consumed is multiplied by the number of actions that you are running. It is important to install Media Server on a server with sufficient resources.

The optimum number of threads to use for processing depends on the number of CPU cores your server has available. Increasing the number of threads used by Media Server up to this limit will increase throughput. For example if your server has 20 CPU cores then allowing Media Server to consume 16 threads rather than 8 should almost double throughput. Using more threads than the server has CPU cores may increase throughput but the improvement will be smaller for each additional thread. Using significantly more threads than the server has CPU cores is not recommended and may decrease performance.

_FT_HTML5_bannerTitle.htm