Optimizing the server

Switch King server has a default configuration that should suit most users.

When adding more and more devices, when data sources are added to the system and rules are set up to control the devices, the complexity in the server increases and might cause longer response time to the clients.

One reason for this is that the server is configured to be able to handle multiple concurrent clients requesting information from the server at the same time. Another reason is that Switch King is using SQLite as database engine. Writing data to the database can sometime cause severe performance hits.

In v0.6 of the server, the response time to clients improved.
The following information primarily applies to v0.5.3 and earlier.

Causes for slow responses from the server

The following situations are examples of what may cause the response rate to drop.

Schedules being recalculated

When the server is recalculating the scheduled events, the clients are put on hold. Recalculation of complext schedules for about 20 devices takes about 200-300ms.
In addition to this, database operations are executed, sometimes adding a second or two to the recalculation time.

In v0.6, recalculation of schedules have been drastically reduced when modifying information in the client. Recalculation of schedules in v0.5 is much more frequent.

Data sources

Colleting data from external data sources has an impact on the performance. The default configuration specifies that the server checks if data is to be collected every 20 seconds.

Schedules controlled by rules

Schedules controlled by rules requires constant evaluation. This consumes CPU time.

Configuration possibilities

In the client

There are settings in the client that directly affect the server. These settings are easy to change.

Send Count

This setting controls the number of repetivive commands being sent to the devices. The higher the number, the more workload is put on the server.
If you have good coverage with your Tellstick, you can lower this number

In the configuration file

The configuration file for Switch King server is named "SwitchKing Service Host.exe.config". It is an Xml file that can be opened in, for example Notepad. The configuration file contains a number of settings that may affect the performance of the server.

Before you make any changes to the server configuration, be sure to make a copy of the configuration file. After saving changes, you need to restart the services.

logStorageLimitHours

<add key="precalcLimitHours" value="24" />

Sets the number of hours (in the future) that the server is to store information about  calculated scheduled events. If you have many schedules in your system, it might be a good idea to lower this value. A value between 6 and 12 is recommended. A lower value results in fewer "upcoming events" being displayed in the client.

logSeverityThreshold

<add key="logSeverityThreshold" value="Status" />

This setting defines the logging level of the server. The default setting - "Status" - is recommended.

pauseBetweenTransmissions

<add key="pauseBetweenTransmissionsMs" value="200" />

This value specifies that the server is forced to pause for 0,2 seconds after a command has being sent to the devices. A lower value is possible, but a value that is to low might do that the USB device can't keep up with the transmissions.

invocationThreadSleep

<add key="invocationThreadSleep" value="600" />

The setting specifies that the server should sleep for i 0,6 seconds between the evaluations of the states for your devices. A higher value results in better response time to the client but may also result in that data in the client is "delayed".

dataCollectorThreadSleep

<add key="dataCollectorThreadSleep" value="20000" />

The setting specifies how often the server should check if there are any data sources set up that are available for collection of data. It is possible to increase this value to, for example 60000 (1 minute).