implementing loops in callback

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

implementing loops in callback

Marc Dirix-2
Hello,

I am currently using pike for automating some testing procedure. The testing procedure automatically covers looping over several measurement parameters. An example is shown below.

In the current setup the actual test is executed by runnin a single process on the host machine by Process.run(); In a new version the process will be run on several machines, simultaneously. To do this I want the test to run in callback mode, where each of the machines can return the test results when they are ready (through http/json).

However, I'm in doubt how to approach the looping over the measurement parameters can be coded effectively. Is it wise to create an array(mapping) and have a callback function run over the array. Or should I create multiple callback functions which call eachother.

What are the thoughts of more experienced pike programmers in this matter?

<code>
for(int nPos=(int)Config->turntable->PositionStart;nPos<=(int) Config->turntable->PositionStop;nPos+=(int) Config->turntable->PositionStep)
{
TT->goPosition(nPos);
foreach(fading,int currfading)
{
MPE->setBypass(currfading);
for(float nAtt=(float)Config->mpe->AttenuatorStart;nAtt<=(float) Config->mpe->AttenuatorStop;nAtt+=(float) Config->mpe->AttenuatorStep)
{
//write("Setting Attenuators to %0.2f\n",(float) nAtt);
foreach(direction,int dir)
{

for (int nRetry=0; nRetry < (int) Config->general->retry; nRetry++)
{
                                           iPerf->RunTest();
                                        }
                                }
                        }
               }
}
</code>

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: implementing loops in callback

Pontus Rodling-2
Hi Marc,

This is probably not the best way of doing it, but it should work with
minimal modification to your test loop.

If you instantiate a Thread.Fifo with a size of maybe 8 or so and then
write your test parameters to it using your already existing loop
(except running it in a separate thread so it doesn't block the default
backend), it'll block when it reaches the limit of the FIFO.

Requests via HTTP can then simply read from the FIFO, which will open up
a new spot for the loop to add test parameters to.

It would be worth to keep track of currently executing tests in case of
an error or timeout on the testing node's end, so the test can be
re-inserted in the FIFO.

Simply keeping track of the amount of generated vs executed tests should
tell you when all tests have finished (after the generator loop is done
of course).

Best regards,
Pontus

On 04/01/2017 03:40 AM, Marc dirix wrote:

> Hello,
>
> I am currently using pike for automating some testing procedure. The
> testing procedure automatically covers looping over several measurement
> parameters. An example is shown below.
>
> In the current setup the actual test is executed by runnin a single
> process on the host machine by Process.run(); In a new version the
> process will be run on several machines, simultaneously. To do this I
> want the test to run in callback mode, where each of the machines can
> return the test results when they are ready (through http/json).
>
> However, I'm in doubt how to approach the looping over the measurement
> parameters can be coded effectively. Is it wise to create an
> array(mapping) and have a callback function run over the array. Or
> should I create multiple callback functions which call eachother.
>
> What are the thoughts of more experienced pike programmers in this matter?
>
> <code>
> for(int nPos=(int)Config->turntable->PositionStart;nPos<=(int)
> Config->turntable->PositionStop;nPos+=(int) Config->turntable->PositionStep)
> {
> TT->goPosition(nPos);
> foreach(fading,int currfading)
> {
> MPE->setBypass(currfading);
> for(float nAtt=(float)Config->mpe->AttenuatorStart;nAtt<=(float)
> Config->mpe->AttenuatorStop;nAtt+=(float) Config->mpe->AttenuatorStep)
> {
> //write("Setting Attenuators to %0.2f\n",(float) nAtt);
> foreach(direction,int dir)
> {
>
> for (int nRetry=0; nRetry < (int) Config->general->retry; nRetry++)
> {
>                                            iPerf->RunTest();
>                                         }
>                                 }
>                         }
>                }
> }
> </code>
>

Loading...