Create unique props variable for each thread in Jmeter - multithreading

I want to create properties variable for each Thread and this is unique and i can use it in another input. So does anyone can suggest me the way to do it? Is __threadNUm is the easiest way to do it?

In order to set the property you can use __setProperty() and __threadNum() functions combination like:
${__setProperty(PROPERTY_PREFIX_${__threadNum},PROPERTY_VALUE,)}
Replace PROPERTY_PREFIX and PROPERTY_VALUE with your own values
To read the property value per thread you can use __P() and __threadNum() functions combination like:
${__P(PROPERTY_PREFIX_${__threadNum},)}
Demo:
Another solution is using Inter-Thread Communication Plugin which is handy for sharing values across different threads (even if they are in different thread groups). The exact instructions will differ depending on what you're trying to achieve, you can see SynchronizationExample.jmx test plan for reference.
You can install Inter-Thread Communication Plugin using JMeter Plugins Manager

Related

Azure durable entity or static variables?

Question: Is it thread-safe to use static variables (as a shared storage between orchestrations) or better to save/retrieve data to durable-entity?
There are couple of azure functions in the same namespace: hub-trigger, durable-entity, 2 orchestrations (main process and the one that monitors the whole process) and activity.
They all need some shared variables. In my case I need to know the number of main orchestration instances (start new or hold on). It's done in another orchestration (monitor)
I've tried both options and ask because I see different results.
Static variables: in my case there is a generic List, where SomeMyType holds the Id of the task, state, number of attempts, records it processed and other info.
When I need to start new orchestration and List.Add(), when I need to retrieve and modify it I use simple List.First(id_of_the_task). First() - I know for sure needed task is there.
With static variables I sometimes see that tasks become duplicated for some reason - I retrieve the task with List.First(id_of_the_task) - change something on result variable and that is it. Not a lot of code.
Durable-entity: the major difference is that I add List on a durable entity and each time I need to retrieve it I call for .CallEntityAsync("getTask") and .CallEntityAsync("saveTask") that might slow done the app.
With this approach more code and calls is required however it looks more stable, I don't see any duplicates.
Please, advice
Can't answer why you would see duplicates with the static variables approach without the code, may be because list is not thread safe and it may need ConcurrentBag but not sure. One issue with static variable is if the function app is not always on or if it can have multiple instances. Because when function unloads (or crashes) the state would be lost. Static variables are not shared across instances either so during high loads it wont work (if there can be many instances).
Durable entities seem better here. Yes they can be shared across many concurrent function instances and each entity can only execute one operation at a time so they are for sure a better option. The performance cost is a bit higher but they should not be slower than orchestrators since they perform a lot of common operations, writing to Table Storage, checking for events etc.
Can't say if its right for you but instead of List.First(id_of_the_task) you should just be able to access the orchestrators properties through the client which can hold custom data. Another idea depending on the usage is that you may be able to query the Table Storages directly with CloudTable class for the information about the running orchestrators.
Although not entirely related you can look at some settings for parallelism for durable functions Azure (Durable) Functions - Managing parallelism
Please ask any questions if I should clarify anything or if I misunderstood your question.

how can i create a property containing a synchronized list which can updated by all threads in JMeter?

i created this list on JSR223 PreProcessor. I access to this list by all the threads but the problem is that it is not synchronized
props.put("listOfTasks", new ArrayList());
someone has any idea how to do it ? thank you
props itself is Properties which inherits from HashTable which is synchronized by nature. More information: Top 8 JMeter Java Classes You Should Be Using with Groovy
What do you store there it's totally up to you, ArrayList per se is not synchronized so you might want to use CopyOnWriteArrayList or call Collections.synchronizedList() function
It's quite hard to give a piece of advice without either seeing your code or background information like what you're trying to achieve, the safest solution from JMeter perspective is working with your list under Critical Section Controller scope, it will allow to avoid any race conditions

Exchanging different kinds of data between threads in Qt

That's kind of design question. Say, I have a worker thread and a GUI thread. The worker thread does some work and the GUI must show the information about current status of this work (for example, worker can process some files and the GUI must show the number of processed files, having separate counters for different types of files).
In Qt the information exchange between threads should be done via signals-slots mechanism. But if I have a lot of different kinds of information to pass from thread to thread, should I create different signals for each type of information (for example, for each type of file), or it would be better to create one signal (for example, informationUpdated(InfoContainer); with a special struct (InfoContainer), which will store the data I want to pass?
It completely depends on what kind of data types you are going to emit.
1- If they are simple non-structured types, you can use QVariant which can handle many types ( primitives and Qt types like QString, QPoint etc)
2- Alternatively, you can use a container class like QMap to pass a list of QVariant as Johannes Schaub said in the comment.
3- You may also want to create your own Message class which is integrated with the meta-object system. Then, convert it to QVariant to be emitted. Here is a good Custom Type Example from Qt documentation.
I choose the last method for better integration and expandability.

JMeter: How to utilize token generated at runtime on multiple thread groups

Scenario is we are generating token during execution which would further be used in other threadgroup.
Like:
In first thread group, tokens will be generated for 100 users.
In second thread group, 50 users will utilize the tokens.
In third thread group, next 50 users will utilize the tokens.
Query is:
1. How do we save tokens that is generated during run time?
2. How to use first 50 tokens on second thread group and rest other 50 on third thread group?
If you need to use a Token generated by a request in following requests then use 1 Thread Group and not many.
Threads in different ThreadGroup have absolutely no relation and are considered as different users, so although you may use elements like InterThreadCommunication to do that, just DON'T.
If you use same thread group then it's just a matter of using the correct extractor to generate variables and then use them using ${varName}.
You can transfer a value between Thread Groups by converting it into a JMeter Property. According to the documentation:
Properties are not the same as variables. Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function.
So if you need to transfer something from one thread group into another:
Convert the value into a JMeter Property using __setProperty() function like:
${__setProperty(foo,bar,)}
Once done the value can be accessed usine __P() function like
${__P(foo,)}
Demo:
If the value is different for different threads - you can combine the above approach with __threadNum() or __counter() functions in order to use current virtual user number or next incremented number as a prefix or a postfix for the function.

Designing a perl script with multithreading and data sharing between threads

I'm writing a perl script to run some kind of a pipeline. I start by reading a JSON file with a bunch of parameters in it. I then do some work - mainly building some data structures needed later and calling external programs that generate some output files I keep references to.
I usually use a subroutine for each of these steps. Each such subroutine will usually write some data to a unique place that no other subroutine writes to (i.e. a specific key in a hash) and reads data that other subroutines may have generated.
These steps can take a good couple of minutes if done sequentially, but most of them can be run in parallel with some simple logic of dependencies that I know how to handle (using threads and a queue). So I wonder how I should implement this to allow sharing data between the threads. What would you suggest the framework to be? Perhaps use an object (of which I will have only one instance) and keep all the shared data in $self? Perhaps
a simple script (no objects) with some "global" shared variables? ...
I would obviously prefer a simple, neat solution.
Read threads::shared. By default, as perhaps you know, perl variables are not shared. But you place the shared attribute on them, and they are.
my %repository: shared;
Then if you want to synchronize access to them, the easiest way is to
{ lock( %repository );
$repository{JSON_dump} = $json_dump;
}
# %respository will be unlocked at the end of scope.
However you could use Thread::Queue, which are supposed to be muss-free, and do this as well:
$repo_queue->enqueue( JSON_dump => $json_dump );
Then your consumer thread could just:
my ( $key, $value ) = $repo_queue->dequeue( 2 );
$repository{ $key } = $value;
You can certainly do that in Perl, I suggest you look at perldoc threads and perldoc threads::shared, as these manual pages best describe the methods and pitfalls encountered when using threads in Perl.
What I would really suggest you use, provided you can, is instead a queue management system such as Gearman, which has various interfaces to it including a Perl module. This allows you to create as many "workers" as you want (the subs actually doing the work) and create one simple "client" which would schedule the appropriate tasks and then collate the results, without needing to use tricks as using hashref keys specific to the task or things like that.
This approach would also scale better, and you'd be able to have clients and workers (even managers) on different machines, should you choose so.
Other queue systems, such as TheSchwartz, would not be indicated as they lack the feedback/result that Gearman provides. To all effects, using Gearman this way is pretty much as the threaded system you described, just without the hassles and headaches that any system based on threads may eventually suffer from: having to lock variables, using semaphores, joining threads.

Resources