ScheduledExecutorService task pausing when going to database (via JPA) - executorservice

In a java EE application I have one scheduledExecutorService with 2 timers on it.
The first via scheduledExecutorService.scheduleAtFixRate(), the second via scheduledExecutorService.schedule().
The first will activate a runnable every 2 seconds, the second will end after 60 seconds.
After the 60 seconds the scheduledExecutorService is stopped, so both timers are gone.
All is working fine with system.out statements in de runnables. But when I put a database read in the runnable of the timer on the 2 second interval the runable is activated only once and looks like to be pausing, the system.out with the read-result is not displayed and schedule is not running the runable every 2 seconds.
After the 60 second, the scheduledExecutorService is stopped and after that the system.out with the result of the database read is shown.
Any idea what may be causing this behaviour?
NB: Based on google-searches I have surrounded the database-read with a try catch catching Throwable but no Throwable is catched...
At first the result of the database was not shown, but that was solved by putting #Stateless and #TransactionType in the class from with the read is actually called.
The actual functionality I try to accomplish is to have two "timers" running. One on a interval of 2 seconds, one only as a count-down max waiting time.
In the 2 second intervals a database check is done to see if a certain value becomes true. If that's the case both timers need to stop and the calling program may continue. If the certain value stays false all the time the calling program may continue if the time of the count-down is done.

Related

Jmeter thread time series with milliseconds frequency

I am trying to build a test plan in JMeter based on a specific thread time series.
For example, I know that at time x, there are n(x) users, and at time x+t, there are n(x+t) users, and so on. The issue is that the number of users has to be updated for t ~= 500ms, and the thread number is in a range of 20 - 200.
Also, ideally, I would like to add and remove threads for the next time slot from the active threads instead of building new threads every time to save resources.
I was trying different tricks to simulate this scenario:
Using execution of Thread Groups sequentially, you can set the duration lifetime but in seconds, every thread will be killed after the specific time slot and recreated in the following thread group.
Using the ultimate thread group, you can define your series of threads for each time interval but still in seconds, and it goes to generate new threads for each timeslot.
In both cases, if you fill the duration box with a value of 0.5, it seems not to recognize it or not work fine.
Do you have any suggestions on how to implement this scenario?
I'm not aware of any Thread Group which has milliseconds precision, but you can try to extrapolate it, for example if you need to add 100 users in 500 ms you can try kicking off 200 users in 1 second and it should be more or less desired load pattern.
The only implementation of thread pool pattern I'm aware of is Throughput Shaping Timer in combination with the Concurrency Thread Group via Feedback Function
And last but not the least there is a possibility to start new threads and stop running ones from JSR223 Test Elements like:
ctx.getThreadGroup().addNewThread(0, ctx.getEngine()) // starts new thread and returns its instance
ctx.getThreadGroup().stopThread('name of the thread', false) // stops the given thread, 2nd argument is for force stop

JMeter - Wait until the predefined time to start next thread

I configured Java based Selenium WebDriver test in Apache JMeter with the following setup:
Number of Threads (Users): 10
Ramp-up period (Second): 120
Loop Count: 1
I ticked the Delay Thread Creation until needed to save resources.
My expectation regarding the functionality:
I expected that if I have 10 users with 120 seconds ramp up time, then every user activity will start each other and the Jmeter will wait at least 12 seconds to start the next thread.
The issue is:
The threads start sometimes within 11 seconds, sometimes 12 seconds.
I don't know why does it happen because I would like to see the threads start after each other exactly in 12 seconds.
The question is
Are there any solution that to tell the JMeter to wait exactly 12 seconds for next thread start?
Here is the picture about started jobs with date time stamp:
I don't think you will be able to achieve this level of precision using ramp-up period approach of the normal Thread Group, a better idea would be going for the Ultimate Thread Group (can be installed using JMeter Plugins Manager) which allows absolute flexibility in terms of definition of ramp-up, ramp-down and time to hold the load.
Example setup:
Example output:
In order to get only one execution of the "job" per each virtual user you can use Throughput Controller configured like:
You can add Flow Control Action for pausing exact time
it allows pauses to be included without needing to generate a sample. For variable delays, set the pause time to zero, and add a Timer as a child.

Coded UI test fails after specific period of time on its own

It goes like this: in my test method, I have 3 Playback.Wait() calls. Each one is set to 2 minutes. Between those waits, I am doing some stuff here and there, - that stuff works, was tested without those 3 waits and is all OK. As soon as 3 waits are there, test method just exists on its own, somewhere during 2nd wait. There is no call stack, no useful info regarding the cause for test termination, nothing. I am pretty much clueless at the moment what is happening. Elapsed time is always 5 minutes, - no more no less.
Do you have any idea what can be wrong?
This is a setting in your .testsettings file, under Test Timeouts section. Specifically, "Mark individual test as failed if its execution time exceeds:", and then gives you fields to enter time in hours, minutes, and seconds. I believe that 5 minutes is the default. You can increase this to fit your purpose, or just remove it entirely (not reccommended).

Orchard CMS custom background job

I created custom background job following instruction.
You can see also discussion regarding this problem.
Created task handler and constructor of task is called every minute. Process method is never called. Also I am getting timeout exception "Orchard.Tasks.BackgroundService - Error while processing background task".
It is interesting that it is possible to add new task, but any query won't work.
I checked table Scheduling_ScheduledTaskRecord and it was locked. I am getting timeout exception in code and SQL Management interface. Lock is released once I turn of site process.
You are describing Scheduled tasks, that run on the background.
In order to trigger the execution of Process you need shcedule the first task (thus starting the loop). Use DateTime.UtcNow to schedule tasks.
You can also use Background Tasks, this way:
public class MyBackgroundService : IBackgroundTask {
public MyBackgroundService() {
}
public void Sweep() {
//Background task execution
//DO some work
}
}
Sweep() will be executed every 60 seconds. I don't know if this suit you, because this will be executed every minute even if the previous task is still running.

jMeter adding threads/users (read from CSV Data) to a running thread group

my problem is quite complex.
The matter is to test our web site answers to an increasing amount of requests from different users.
So I can take users/passwords from a CSV Data and launch an HTTP request (with variables readen from the file).
But I don't want to run the thread with all users at same time, but to loop and add at every iteration an other user from the file to the running thread groups (after some delay).
It seems very difficult to do so with jMeter. Perhaps I's need to call a custom java class ?
If I understand you correctly, you just should use Rump up. This parameter control how fast your test will reach maximum threads count.
As explained in JMeter documentation,
The ramp-up period tells JMeter how long to take to "ramp-up" to the
full number of threads chosen. If 10 threads are used, and the ramp-up
period is 100 seconds, then JMeter will take 100 seconds to get all 10
threads up and running. Each thread will start 10 (100/10) seconds
after the previous thread was begun. If there are 30 threads and a
ramp-up period of 120 seconds, then each successive thread will be
delayed by 4 seconds.
Also may be this Throughput Shaping Timer may be helpful for you. You can schedule duration of request with it.
As Jay stated, you can use ramp up to try to control this, though I am not sure the result will be what you are after...though it will add the startup delay. If you have a single thread then each row of the CSV will be processed one at a time, in order.
You can set the thread group to 1 thread and loop forever. In the CSV config you can set a single pass and to terminate the thread on EOF.
CSV Data Set Config-->Recycle on EOF = False
CSV Data Set Config-->Stop thread on EOF = True
Thread Group-->Loop Count = Forever
Also keep in mind that by using BSF and Beanshell you can exact a great deal of control over JMeter.
You should check out UltimateThreadGroup from jmeter-plugins.

Resources