Synchronization

Synchronization is useful in testing the effects of a large number of simultaneously called transactions. It allows you to create stress on your system to test specific concurrency issues. Synchronization works by employing an additional user called an Event Starter, which functions like the starting gun at the beginning of a race. Using the CreateEvent function, you can use the Event Starter user to send an Event object after a specified period of time. You can set up the users in the simulation to wait for this event and thus perform a specified transaction simultaneously when the event is released. Silk Performer provides the PulseEvent function for this purpose.

The other users call the WaitForSingleObject function to wait until the specified event is in the signaled state. Using the WaitFor function, users are able to synchronize themselves without the use of event objects.

Synchronization Functions

The following functions are used in serializing synchronizing and users:

  • CreateEvent
  • PulseEvent
  • WaitFor
  • WaitForSingleObject
  • CloseHandle

Synchronization Sample Script

In the following example, the users create an event object called StarterEvent and establish a connection to an FTP server. The Starter user sets the state of the event object StarterEvent to signaled every ten seconds and resets it after the appropriate number of waiting users process the transaction. In this way, all the Uploader users are forced to execute the TUpload transaction at the same time. The Uploader's wait until the event object is in the signaled state, and then execute their Upload transaction.

dcluser
  user
    Starter
  transactions
    TInit : begin;
    TStartEvent : 20;
  user
    Uploader
  transactions
    TInit : begin;
    TUpload : 20;
var
  hEventGo : number; // handle for starting event
  hFTP : number;

dcltrans
  transaction TInit
  begin
    hEventGo := CreateEvent("StarterEvent");
    WebFtpConnect(hFTP, "standardhost", WEB_PORT_FTP, "username", "password");
  end TInit;

  transaction TStartEvent
  begin
    wait 10.0;
    // every 10 seconds the starter event forces all
    // seller users to execute the selling transaction
    // at the same time
    PulseEvent(hEventGo);
  end TStartEvent;
  
  transaction TUpload
  begin
    WaitForSingleObject(hEventGo, INFINITE);
    WebFtpPut(hFTP, 4096, "test.dat", true);
  end TUpload;