Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Titan » Advanced TTCN-3 usage: busy wait vs. non-busy wait in altsteps(How to efficiently not do anything while waiting for a message)
Advanced TTCN-3 usage: busy wait vs. non-busy wait in altsteps [message #1737077] Tue, 05 July 2016 14:14
Kristof Szabados is currently offline Kristof SzabadosFriend
Messages: 30
Registered: July 2015
Member
One of the worst performance problems in TTCN-3 are caused by busy waiting.
These are bad as busy wait looks very innocent in the code, but drains all computational resources, where there is actually no need for it.

The following 2 example testcases will do the exact same functionality (waiting for an incoming message), with very different performance profile:
private function f_functionName( )
runs on altstepExample_CT
{
  timer TL_t1 := 15.0;
  TL_t1.start;
  TL_t1.timeout;
  portname_PT.send( 5 );
}

// demonstrates busy wait
private testcase tc_busyWait()
runs on altstepExample_CT
system altstepExample_CT
{
  var altstepExample_CT vl_ptc := altstepExample_CT.create;
  connect(self:portname_PT, vl_ptc:portname_PT);
  vl_ptc.start( f_functionName() );
  
  alt {
    [] portname_PT.receive(integer:*) {}
    [else] {
      repeat;
    }
  }
  
  disconnect(self:portname_PT, vl_ptc:portname_PT);
  vl_ptc.stop;
}

// demonstrates non-busy waiting
private testcase tc_non_busyWait()
runs on altstepExample_CT
system altstepExample_CT
{
    var altstepExample_CT vl_ptc := altstepExample_CT.create;
  connect(self:portname_PT, vl_ptc:portname_PT);
  vl_ptc.start( f_functionName() );
  
  alt {
    [] portname_PT.receive(integer:*) {}
  }
  
  disconnect(self:portname_PT, vl_ptc:portname_PT);
  vl_ptc.stop;
}


When executed tc_non_busyWait will just wait 15 seconds for an incoming message, without using any processor power.
tc_busyWait will also just wait 15 seconds for an incoming message, but during that 15 seconds one computational core on the executing machine will experience 100% load (and the users an unresponsive machine )

The problem comes from using the repeat statement in the else part of an alt statement.
The else branch is executed whenever the other alt branches can not, and the repeat statement forces the re-evaluation of all of the alt branches.
In effect this structure creates a loop, that can only be broken when one of the alt branches can be executed.
And no matter how cheap the snapshot evaluation mechanism is ... it will be forced to re-execute as soon as it finishes, overloading the machine.

In comparison tc_non_busyWait will just silently wait until a message arrives on the connected port, and do the evaluation only then.
Simple and efficient.
Previous Topic:Is it possible to execute ttcn3 test cases via cli?
Next Topic:Advanced TTCN-3 usage: The secret life of shorthand notations
Goto Forum:
  


Current Time: Wed Sep 19 13:17:33 GMT 2018

Powered by FUDForum. Page generated in 0.01614 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top