# Load Balancing Using Core Assignments

This feature enables you to perform load balancing by designating that only certain types of work executes on specific processor cores. In other words, the Windows Scheduler will only run the unit of work on the core that you specify.

When using this feature In conjunction with a strategic load balancing strategy, you reduce potential spikes in application execution time. Keep in mind, however, that limiting execution of work to a specific core can also reduce overall application throughput.

It is likely you will have to experiment with settings and monitor the results, making adjustments, until you achieve an optimal result.

## Basics of Load Balancing

While there are many technical articles available that detail how Windows schedules and executes processor workloads, the following concepts are essential to understand before attempting to assign cores to specific units of work.

- Without assigning specific cores, Windows initially schedules work simultaneously on all cores, running in tandem.
- Windows will occasionally "double-up" loads on specific cores, resulting in increases in execution time, or "spikes".

By assigning specific work to specific cores, you can control or tune Windows load balancing behavior when running specific or general Tasks in Cognex Designer.

## Types of Work You Can Assign to Specific Cores

Only the following types of work can be assigned to specific cores. The bolded strings after each bullet point indicate the type of work specified in the Core Assignment area of the Processor Settings dialog. See the next section for details on assigning work to cores.

- Tasks (includes the parallel region) (Task)

- Asynchronous Image recording (Image Recording)

- Web HTTP request processing, for example Tag value updates to WebHMI applications. (Web)

- Primary UI threads, for example rendering of images, button-click events, etc. (UI)

## Assigning Work to Specific Cores

1. Open the Project Settings dialog by clicking System > Settings in the Explorer pane. Select the Performance tab.
2. In Processor Settings, set Expected Cores to the number of cores you want to make available to Cognex Designer. By default the selected number of cores is the maximum number of cores available on your computer.
Note: We recommend using the default unless the computer on which you are developing your application has a different number of cores than the end-user deployment computer.

In this case, use the Expected Cores field to set the maximum available physical cores available on the deployment system.

For example, you may be deploying to a computer with a maximum of 2 cores, while your development computer has 4 cores available. In this case, you would set Expected Cores to 2.

3. Allocate different types of work to specific cores using the checkboxes in the Core Assignment area of Processor Settings. A typical set-up on a computer with Expected Cores of 2 would be to assign the Web, UI and Image Recording work to Core 0. Time-critical vision tasks (such as a custom Task named DetectFlavor) can then be free to run on the remaining Core 1, unhindered by the processing load from the Web, UI and Image Recording workload. See the graphic below for an example of this set-up.

Note that in this example the workload in the windows labeled DetectFlavor and Task are allocated to Core 1, while the Image Recording, UI, and Web workloads run on Core 0.

Note: You must give all work listed in the Core Assignment area a specific core assignment. In other words, no work item may have any Core x boxes unchecked.

## Other Considerations When Assigning Cores

- If you set Expected Cores lower than actual available cores, only the Expected Cores you set are displayed.

- If you set Expected Cores to higher than actual available cores, as in the Note above, assure all your work is allocated to a specific core. You can leave cores unused, but all listed work (each horizontal line in the Core Assignment table) must be allocated to a specific core.

  Test your core assignments thoroughly on a machine that replicates the core configuration on the deployment computer. it may be necessary to test extensively, monitoring the performance results, before deploying a customized core assignment solution, as results can vary in various network configurations. Know as much about your deployment configuration and environment as possible before deploying.