Forum Discussion

sinnes_1's avatar
sinnes_1
Occasional Contributor
15 years ago

"Unique" ids for load test threads?

Hi,

I have a requirement to run a load test on a webservice, with the catch being that each thread needs to refer to a different variable each run.
I can provide a list of values I need and write a script to process that, but when doing it as a load test, all threads will process the same file.
Is there any way I can split is this out so I can ensure each thread is dealing with different values? I thought I could add some degree of logic if each thread could somehow be given a unique id or something similar.

Any thoughts/ideas?

2 Replies

  • sinnes_1's avatar
    sinnes_1
    Occasional Contributor
    I think I've answered my own question. I didn't google hard enough

    def threadIndex = context.ThreadIndex;


    This will set threadIndex to be the index number of the thread. Example groovy script:

    def threadIndex = context.ThreadIndex;
    System.out.println("Hi, I'm thread "+threadIndex);


    If you run that as a load test with 5 threads, your output will look something like this:


    Hi, I'm thread 2
    Hi, I'm thread 0
    Hi, I'm thread 1
    Hi, I'm thread 4
    Hi, I'm thread 3
    Hi, I'm thread 0
    Hi, I'm thread 1
    Hi, I'm thread 2
    Hi, I'm thread 4
    Hi, I'm thread 3


    Now, where can I find the different values I can get from context??
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    If you need to find out what context variables are available, you can utilize the Map interface that the Context implements. Either do "log.info context" to print out the entire contents of the context, or "log.info context.keySet()" for the variable names.

    Regards,
    Dain
    eviware.com