JMeter - How to handle Long polling transport request method - jmeter

In my Jmeter script request which contains the 'LongPolling' transport method and it takes a high load time or response time
Also, the response message content value is used for the next consecutive request. How can I handle that scenario?
I don't want this my wait time for the server response

JMeter thread model assumes that a thread (virtual user) always waits for the previous sampler to fully complete before starting the new one.
The easiest solution is moving your "long-polling" requests into a separate thread group and if you need to pass data between thread groups either use __setProperty() and __P() functions combination or go for Inter-Thread Communication Plugin
If you need to have everything within the single Thread Group - you can consider using Parallel Controller, however it might not be fully suitable for your needs as it is still a Sampler hence it waits for all its children completion prior to proceeding
Depending on your use case you can find jmeter-asynchronous-http plugin useful, see How to Load Test Async Requests with JMeter article for more details if needed.

Related

Jmeter ,Way to call rest API for every 3minutes to get Auth token

I am working on setting up a way to do a performance test for the rest API's using Jmeter which includes token expiry for every three minutes.
1.)Currently, I created two thread groups one for making a call to get "access_token" and setting into the property using Bean shell assertion setProperty, to be used in other thread Groups.
2.)I could see Second thread group can access the value set in the first step.
But my goal is to execute the first thread group every 2min 30 seconds continuously so that the second thread group can get the new token every 2 min 30 seconds.
I tried a constant timer, but didn't seem to work is there any way to do this or any other timer to use to achieve this token refresh?
Thanks in advance
The Constant Timer should work, but be aware that it creates a delay before each Sampler it it's scope so it might be the case your setting it up wrong, you can use i.e. a Dummy Sampler and put the Constant Timer as a child of the Dummy Sampler, this way your HTTP Request to get token will be executed, followed by the delay defined in the Constant Timer, followed by the Dummy Sampler, et.c
Example setup:
You might find Flow Control Action sampler easier to use
Also be aware that starting from JMeter 3.1 you're supposed to be using JSR223 Test Elements and Groovy language for scripting. Moreover it's not required to write any code, you can go either for __setProperty() and __P() functions combination or for Inter-Thread Communication Plugin

JMeter - Recurring request every x seconds without blocking other requests

I'm trying to load test our web app server side with JMeter, everything works so far except one thing.
I have a heartbeat loop the app client side that pings the server every x seconds.
I tried the while processor but then the thread is just "stuck" there (as expected).
Is there a way to execute a request every x seconds while the other requests are still executing?
I also would need access to the variables of my thread since the heartbeat sends a unique id, so another thread group won't work as far as i understand.
The id is read from one of the first request responses into a variable so the heartbeat requests should only start when this variable becomes available.
Another separate Thread Group to send heartbeat requests is the easiest way to achieve, if you need to pass a value from the "main" thread group you can do it in 2 ways:
Use __setProperty() function in the "main" thread group to convert the variable into a property and use __P() function in 2nd Thread Group to read the value. If you have more than 1 thread it makes sense to add __threadNum() function to make the value thread-specific.
Use Inter-Thread Communication Plugin if you don't mind using JMeter Plugins

How to start a Jmeter thread from another thread?

I have Thread A that performs user login, setting some settings and creating some records. While working on the records page, there is a background thread, Thread B, that is being called every 15s, performs some sort of sycnronisation, but only when I'm on the records page.
What I managed to do is created a second thread that will fire these requests each 15s. Using a BeanShell PreProcessor I share the cookies between the two threads, so that the Http cookie manager in the second thread uses the same variables/values as the first one. My requests are working fine.
What I can't figure out is how to trigger Thread B when the Thread A has reached the step that involves records. One option is to delay Thread B for a certain amount of time, but this isn't very reliable as I can't know before hand how long it takes Thread A to finish creating the users.
Is there a way to trigger a thread from another thread?
Take a look at Inter-Thread Communication Plugin - it allows synchronizing actions between different threads (even if they are in different thread groups) basing on a simple FIFO queue.
The logic would be:
When you did some action by Thread A put something into the queue using fifoPut function
Thread B will be scanning the queue and if anything comes up it will get the value and start execution of its own actions.
Check out SynchronizationExample.jmx test plan for reference implementation.
You can install Inter-Thread Communication plugin using JMeter Plugins Manager
Also be aware that starting from JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting so kindly avoid Beanshell going forward.

Run Multiple requests of single thread group concurently

I want to simulate a scenario in which a page contains multiple requests for differ data. All runs concurrently. I created a Thread Group with all those requests and ran it for 10 users(Threads) in 0sec ramp up time. But in this Test Plan all users starts concurrent but they all process requests in sequential way i.e.(always completes first request then starts 2nd,then third,so on).
I want that all requests of each user starts at same time then completes according to their response time (Like if 3rd takes less time than first then it should complete before 1st and 2nd). I have tried Synchronize time.
I don't think it is possible at the moment, the relevant enhancement is being tracked as Bug 53159
In the mean time you have 2 options:
Use different Thread Groups to kick off the requests. If you need to synchronize the requests you can use i.e. Inter-Thread Communication plugin.
Develop some custom code using JSR223 Sampler or even create your custom sampler, see How to Load Test AJAX/XHR Enabled Sites With JMeter for details on how this can be done.

Jmeter Request Execution

I am trying to understand jmeter's core behavior.
Say I am executing a HTTP request (single user and single sampler but different variable values) in infinite loop.
In the above case does jmeter send a request and waits for the response before sending the next request OR it sends the requests without waiting for response?
Jmeter uses a thread-based model where each thread will wait for a response before sending another request. In other words it will only drive the load as fast as application can take it.
In JMeter you specify a number of threads in a ThreadGroup which equate to virtual users, and the threads attempt to execute the script as many times as possible.
If you want to maintain a constant rate, you can use multiple threads and use a Constant Throughput Timer to set the request rate: if there are enough threads, it should be possible to maintain the rate even though some threads are waiting for a response. Here belongs also custom Throughput Shaping Timer which is more flexible.
Another possibility seems to be to use e.g. either Ultimate Thread Group or Stepping Thread Group from jmeter plugins.
In this context you can also look onto the Response Timeout field available for any jmeter's sampler - number of milliseconds to wait for a response.

Resources