Jmeter - All threads other than current thread wait - multithreading

I am new to Jmeter and I have been struggling with my test plan.
Test plan steps:
Enters the site
Creates multiple wish lists (like the wish list on amazon)
In the wish list dashboard the order of the list is constantly updated based on the most recently -edited list on the top of the page
I have multiple threads entering this dashboard and editing the wish lists
I am using multiple if statements to validate the position of the wish list (based on name) the current thread wants to modify.
Problem:
The problem is that after that if statement when I try to click edit (POST request) on the desired wish list associated with the current thread the page crashes
The reason behind the crash is a race condition. Before I can post the position of the page, the location changes (another thread has created or modified a wish list)
I have tried using Critical Section Control but that will not work be because the other thread can be working on editing the wish list which can change the order on the dashboard.
Question:
Is there a way on Jmeter where I can pause the all the thread other than the current thread when I am at the Dashboard Post request?

If your application should allow concurrent modification of the same wish list by different users - it's an application bug which needs to be resolved
If your application doesn't allow concurrent modification of the same wish list by different users - your test is badly designed, you need to amend it and ensure that each thread (virtual user) is using different wish list. There is __threadNum() function which allows getting the ID of current thread (virtual user), you can use this information in order to distinguish users/threads
If your scenario is more complex you can consider using i.e. Inter-Thread Communication Plugin, you can implement whatever scenario of IPC you want using it. Inter-Thread Communication Plugin can be installed using JMeter Plugins Manager

You can use the Critical Section Controller to execute a single or multiple requests in a thread by a single thread in a thread group.Critical Section Controller takes control over a single JVM. Hence it is not suitable if you are in distributed testing.

Related

Is it possible to run equivalent of a separate thread in Node.js to periodically perform async tasks automatically?

I understand that Node is essentially single threaded, but is there a way to achieve the kind of automated async behaviour that you could achieve in, for example, a Java Spring application by just sparking off a new Thread (or similar)?
My actual requirement is to periodically - and without prompting from a user event - iterate through various caches and selectively refresh only the data that has expired. The refresh itself can take some time, so ideally I don't want to wait until the user clicks before it decides to clean up the cache.
Alternatively, if there is a way to achieve this without having to create a completely independent thread, please enlighten me.
You can use cluster npm, so it will create multiple thread.
Using cluster it will create co worker
Ref code click here
Use can use webworkers threads API of JS to implement this functionalty. Refer to the npm package for more information webworker-threads

How do you run multiple requests or thread groups parallely "for each of the same user" in JMeter

Adding multiple requests to same thread group also seem to run sequentially.
I know you can start thread groups in parallel but I want all thread groups to run or start in parallel for the SAME user.
And then you have the synchronizing timer that starts multiple users at the exact time
http://jmeter.apache.org/usermanual/component_reference.html#Synchronizing_Timer
But this does not scale all users concurrently based on throughput and is very hacky i.e., you have to parameterize your users and the group by in such a way to match expected throughput and number of requests per user
Right now, the work around is to create an HTML page to trigger download embedded resources in parallel for same user in one thread group but that is ugly and only works for GET requests. Also this is very buggy and runs very slow besides occupying full CPU and the throughput is 1/10th of a separate parallel test showing that this does not work correctly.
You could use the same approach as for AJAX testing with JMeter which assumes running multiple requests of different types at the same moment of time. It assumes some scripting so you will have to write a bit of Groovy or Java code in JSR223 Sampler or even create your own sampler, fortunately JMeter module plugin-oriented architecture is very extension-friendly as it evidenced by JMeter Plugins project (take a look by the way, perhaps your use case is already implemented)
See How to Load Test AJAX/XHR Enabled Sites With JMeter guide for explanation of the approach and few code snippets demonstrating how to run parallel asynchronous requests

What is the best approach for long running Java code in an XPage?

So I have some Java code that takes some time to complete (about 2 minutes). Nothing I can do about that.
But I am wondering how best to approach this in the XPages UI so that the user may still have to wait but has more control/interaction while it is running (not just a spinning wheel).
So from what I can see I can do the following.
Java class called in XPage wrapped in a thread.
Java Agent called from XPage in a thread.
Java Agent called from an XPage, but waits for a document to be updated.
Eclipse plugin (For in the client) is activated. Not sure how it would talk back to XPage though (via document?).
Any other methods?
If you created the thread in the XPage, is that going to cause any problems at the server end? Will I have to avoid using Notes objects in the Java class?
I would suggest using the OSGi Tasklet service, a.k.a. DOTS. This approach allows Java tasks to be scheduled or bound to events, just like agents, but perform significantly more efficiently than agents. Perhaps most pertinent to your need is the additional ability to trigger DOTS tasks via the console, which would allow your XPages code to start the Java code merely by issuing a remote console command via the session object.
In addition, check out the technique used in the XSP Starter Kit to provide a serverScope variable. If your code is running in a DOTS task (or even an agent), it's running in a different Java application, so it can't talk directly to the standard scope variables. The serverScope approach would theoretically allow you to store objects that can be accessed from both the XPage and the triggered task. This could aid in using Mark's technique, as mentioned above by Per, to convey progress to the user while the task is running: you'd just be storing the progress information in serverScope instead of sessionScope.
A solution would be to have an agent react on saving new documents in the database instead of kicking of the agent in your application and use threads ( because threads can be very dangerous and could easily kill your http task )
Another thing you could look into is why the code that you want to execute is taking 2 minutes to complete. What is the code for? Doing things in other databases or connect to other non notes resources?

Delphi - Creating a control that runs in its own process

HI
I have a control that accesses a database using proprietary datasets. The database is an old ISAM bases database.
The control uses a background thread to query the database using the proprietary datasets.
A form will have several of these controls on it, each using their own thread to access the data as they all need to load simultaneously.
The proprietary datasets handle concurrency by displaying a VCL TForm notifying the user that the table being opened is locked by another user and that the dataset is waiting for the lock to be released.
The form has a cancel button on it which lets the user cancel the lock wait.
The problem:
When using the proprietary datasets from within a thread, the application will crash, hang or give some error if the lock wait form it displayed. I suspect this is to do with the VCL not being thread safe.
I have solved the issue by synchronizing Dataset.Open however this holds up the main thread until the dataset.open returns, which can take a considerable amount of time depending on the complexity of the query.
I have displayed a modal progress bar which lets to user know that something it happening but I don't like this idea as the user will be sitting waiting for the progress bar to complete.
The proprietary dataset code is compiled into the main application, i.e. its not stored in a separate DLL. We are not allowed to change how the locking works or whether a form is displayed or not at this stage of the development process as we are too close to release.
Ideally I would like to have Dataset.open run in the controls thread as well instead of having the use the main thread, however this doesn't seem likely to work.
Can anyone else suggest a work around? please.
Fibers won't help you one bit, because they are in the Windows API solely to help ease porting old code that was written with cooperative multitasking in mind. Fibers are basically a form of co-routines, they all execute in the same process, have their own stack space, and the switching between them is controlled by the user code, not by the OS. That means that the switching between them can be made to occur only at times that are safe, so no synchronization issues. OTOH that means that only one fiber can be running within one thread at the same time, so using fibers with blocking code has the same characteristics as calling blocking code from within one thread - the application becomes unresponsive.
You could use fibers together with multiple threads, but that can be dangerous and doesn't bring any benefit over using threads alone.
I have used fibers successfully within VCL applications, but only for specific purposes. Forget about them if you want to deal with potentially blocking code.
As for your problem - you should make a control that is used for display purposes only, and which uses the standard inter-process communication mechanisms to exchange data with another process that accesses your database.
COM objects can run in out-of-process mode. May be in delphi it will be a bit easier to use them, then another IPC mechanisms.

Thread Safe web apps - why does it matter?

Why does being thread safe matter in a web app? Pylons (Python web framework) uses a global application variable which is not thread safe. Does this matter? Is it only a problem if I intend on using multi-threading? Or, does it mean that one user might not have updated state if another user... I'm just confusing myself. What's so important with this?
Threading errors can lead to serious and subtle problems.
Say your system has 10 members. One more user signs up to your system and the application adds him to the roster and increments the count of members; "simultaneously", another user quits and the application removes him from the roster and decrements the count of members.
If you don't handling threading properly, your member count (which should be 10) could easily be nine, 10, or 11, and you'll never be able to reproduce the bug.
So be careful.
You should care about thread safety. E.g in java you write a servlet that provides some functionality. The container will deploy an instance of your servlet, and as HTTP requests arrive from clients, over different TCP connections, each request is handled by a separate thread which in turn will call your servlet. As a result, you will have your servlet being call from multiple threads. So if it is not thread-safe, then erroneous result will be returned to the user, due to data corruption of access to shared data by threads.
It really depends on the application framework (which I know nothing about in this case) and how the web server handles it. Obviously, any good webserver is going to be responding to multiple requests simultaneously, so it will be operating with multiple threads. That web server may dispatch to a single instance of your application code for all of these requests, or it may spawn multiple instances of your web application and never use a given instance concurrently.
Even if the app server does use separate instances, your application will probably have some shared state--say, a database with a list of users. In that case, you need to make sure that state can be accessed safely from multiple threads/instances of your web app.
Then, of course, there is the case where you use threading explicitly in your application. In that case, the answer is obvious.
Your Web Application is almost always multithreading. Even though you might not use threads explicitly. So, to answer your questions: it's very important.
How can this happen? Usually, Apache (or IIS) will serve several request simultaneously, calling multiple times from multiple threads your python programs. So you need to consider that your programs run in multiple threads concurrently and act accordingly.
(This was too long to add a comment to the other fine answers.)
Concurrency problems (read: multiple access to shared state) is a super-set of threading problems. The (concurrency problems) can easily exist at an "above thread" level such as a process/server level (the global variable in the case you mention above is process-unique value, which in turn can lead to an inconsistent view/state if there are multiple processes).
Care must be taken to analyze the data consistency requirements and then implement the software to fulfill those requirements. I would always err on the side of safe, and only degrade in carefully analyzed areas where it is acceptable.
However, note that CPython runs only one thread context for Python code execution (to get true concurrent threads you need to write/use C extensions), so, while you can get a form of race condition upon expected data, you won't get (all) the same kind of partial-write scenarios and such that may plague C/C++ programs. But, once again. Err on the side of a consistent view.
There are a number of various existing methods of making access to a global atomic -- across threads or processes. Use them.

Resources