Table of Contents

Tuning

Threading

Library creates for each connected client 3 worker threads that handle received request PDUs and call corresponding event handlers, f.i. evSubmitSm, evDeliverSm.

Note

Since version 2.9.15 the TaskScheduler.Default (thread pool) is used by default.

You can increase the number of worker threads for each client.


var scheduler = _client.ReceiveTaskScheduler as WorkersTaskScheduler;
if (scheduler != null)
    scheduler.WorkerCount = 10;

When your application establishes a lot of SMPP sessions, you may want to create a global task scheduler and set required number of worker threads for the process.

var scheduler = new WorkersTaskScheduler(100);

You need then assign this scheduler to the client. It is your responsibility to dispose the scheduler instance.

Before SmppClient connects to remote host.

client.ReceiveTaskScheduler = scheduler;

For the SmppServer when client connects.

public void server_evClientConnected(object sender, SmppServerClient client)
{
    client.ReceiveTaskScheduler = _scheduler;
}

TaskScheduler.Default can be used as well. In this case all event handlers for received requests will be scheduled to ThreadPool.

_client.ReceiveTaskScheduler = TaskScheduler.Default;

You can force the thread pool to create more worker threads with the command

   ThreadPool.SetMinThreads(200, 200);

It is especially useful for the SmppServer to improve performance immediately after start.

Networking

To reduce number of calls to network adapter and increase transfering speed, you can change receive or send buffer size for the TCP socket:

_client.ReceiveBufferSize = 32 * 1024 * 1024;
_client.SendBufferSize = 32 * 1024 * 1024;

A larger buffer size might delay the recognition of connection difficulties. Consider increasing the buffer size if you are using a high bandwidth, high latency connection (such as a satellite broadband provider).

Memory

Memory consumption for a client can be reduced if you limit the number of requests received from the client but not processed by the application.

_client.ReceivedRequestQueueLimit = 1000;

If a client sends PDUs too fast, the library stops reading from network until a free slot is available in the receive queue. This is commonly referred to as "flow control" or "back pressure". This is also affects the responses sent by the client. They won't be read from network because of reading delay.

The number of request waiting for response from remote side can be also limited with the code

_client.SendQueueLimit = 1000;

The incomplete request objects consume memory of the running process. This property helps to reduce memory consumption and prevent unsuccess responses. When remote side cannot process messages fast enough, number of sent messages may exceed queue limit (ESME_RMSGQFUL). When this property is defined the sending to network will be delayed until the queue has a free slot (remote side has sent a response).