I need JMeter to simulate 28 days of activity (via altering time stamps) in under 1 day. There is is time function, but it doesn't look like there is one that supports anything other than current time. I also don't want to fake the dates because things like leap years and what month it is will make it incorrect.
So how can I get a time format as a delta of the current time (in milliseconds from epoch), and/or what is the best way to run a 1 day load test as if time was going 28 times faster?
UPDATE:
Thanks Dmitri T! I was able to modify your answer to what I needed (I have to restrict what hours events occur between 8am and 5pm)
For those that need it, I used the following in a JSR223 PreProcessor
timestamp=new Date();
timestamp.setDate(timestamp.getDate() - Math.floor(Math.random() * (28)));
timestamp.setHours(8,0,0,0);
timestamp.setTime(timestamp.getTime() + Math.floor(Math.random() * (1000*60*60*9)));
vars.put("TIMESTAMP", timestamp.toISOString());
You can simulate this using __time() and __longSum() functions combination like:
Now: ${__time(,)} - I guess you are already aware of it
Now + 28 days: ${__longSum(${__time(,)},2419200000,)} - where 2419200000 is
1000 * 60 * 60 * 24 * 28
^ ^ ^ ^ ^
ms sec min hour day
If Unix timestamps don't play for your for some reason you can use __javaScript() function to convert them to human-readable format like:
${__javaScript(new Date(${__longSum(${__time(,)},2419200000,)}),)}
Demo:
References:
Functions and Variables
The Function Helper Dialog
How to Use JMeter Functions
Related
I'm using Laravel 5.8 and I like to auto-generate Invoices should be generated auto from Monday - Sunday.
every Sunday night at 23:59:00
Let's say I have
"23:59:00 according to the region time zone".
Every store is related to a region, from the region table you'll find the time zone.
Questions
How should I set the CRON JOB so I can generate invoices automatically according to the list of timezone I will get from the table?.
I have two suggestions;
if you want it to be static, define each command with the corresponding timezone from your database. Different timezones may have same time such as Europe/Amsterdam and Europe/Berlin
$schedule->command('generate:report')->timezone('one-of-the-timezone')->at('23:59');
$schedule->command('generate:report')->timezone('another-timezone')->at('23:59');
$schedule->command('generate:report')->timezone('yet-another-timezone')->at('23:59');
$schedule->command('generate:report')->timezone('some-other-timezone')->at('23:59');
If you want it to be dynamic, make it run every 59. min hourly and try to match it with the timezones via using hour.
$schedule->command('generate:report')->hourlyAt(59);
Inside your command class;
public function handle(TimezoneRepository $timezoneRepository)
{
$timezones = $timezoneRepository->getUniqueTimezones(); // the unique timezones in your database - cache if you want
foreach ($timezones as $timezone) {
$date = Carbon::now($timezone); // Carbon::now('Europe/Moscow'), Carbon::now('Europe/Amsterdam') etc..
if ($date->hour === 23) { // you are in that timezone
$currentTimezone = $date->getTimezone();
dispatch(new ReportMaker($currentTimezone)); // dispatch your report maker job
}
}
}
With the dynamic one, you will hit to multiple timezones at one iteration(when generate:report is executed) as i said at then beginning.
one of the possible flaw may be; if the execution of getting timezones etc takes more than 1 minute you may be in 00:00 instead of 23:59. It is better to calculate your report asynchronous and cache the list of timezones to not face problems while executing this loop.
Another possible flaw;
According to wiki;
A few zones are offset by 30 or 45 minutes (e.g. Newfoundland Standard Time is UTC−03:30, Nepal Standard Time is UTC+05:45, Indian Standard Time is UTC+05:30 and Myanmar Standard Time is UTC+06:30).
If you want to cover any of these, then it is better to execute the command like this
$schedule->command('generate:report')->cron('14,29,44,59 * * * *');
and make both hour and minute comparison such as;
$date->hour === 23 && $date->hour === 59
You can use the timezone() method in your task Schedulding
Using the timezone method, you may specify that a scheduled task's
time should be interpreted within a given timezone:
$schedule->command('report:generate')
->timezone('America/New_York')
->at('02:00')
How can I get current time in 24 hours format in JMeter.
I tried ${__time(hh:mm a,)} but it results in AM/PM format.
As per How to Use JMeter Functions guide JMeter's __time() function output can be controlled via SimpleDateFormat class patterns.
Looking into JavaDoc:
you don't need a letter
you need to use capital H for 0-24 hours or lowercase k for 1-23 hours
So change function to ${__time(HH:mm,)} and that should be it
In Apache JMeter 5.2, current time can be captured in User defined variable and then used in Rest payloads as following screenshot:
expression - ${__timeShift(yyyy-MM-dd'T'HH:mm:ss'.000+05:30',,PT0S,,)}
output - "2020-06-06T18:10:59.000+05:30"
Here, date and time format can be changed as per the need.
Once current date and time is captured in user defined variable then it can be used as "${now-date-time}" in REST requests.
It could also be possible that we face a scenario where there should be gap of, let's say, 1second between start time and end time while constructing request. In such case, following expressions can help:
now-date-time : ${__timeShift(yyyy-MM-dd'T'HH:mm:ss'.000+05:30',,PT0S,,)}
now-date-time-plus-one-second : ${__timeShift(yyyy-MM-dd'T'HH:mm:ss'.000+05:30',,PT1S,,)}
Following example better explains it:
I am implementing an express session with rethinkdb and I have an 'expires' field that is calculated as so: r.now() + 24 * 60 * 60 * 1000 (1 day from now).
Can I do something like this?
r.now().add(millisecondsToAdd)
There is no api documentations for this.
It will also be useful for querying.
Note: I am using the official Javascript driver.
You can do that
r.now().add(24*60 * 60 * 1000)
However, it's second, not millisecond. So to add one one more day, it is:
r.now().add(24*60*60)
When you browser the API, add saying about time: https://www.rethinkdb.com/api/ruby/add/
time.add(number[, number, ...]) → time
sub works similar to add btw.
I have a spring batch application and i am using CRON to set how often this application runs. But the problem i am running into is that i want to run the job on specific hours
3 am
7 am
11 am
3 pm
7 pm
11 pm
As you can see it is every 4 hours but starts at 3 am so i cannot use */4 in the hours section of the timing format as this would start the job at 4am
I have also tried '3,7,11,15,19,23' in the hours section but this does not work either (guessing it only works in the minutes section). Does someone know how i can do this?
Use
#Scedule(cron="0 0 3/4 * * ?")
The Pattern x/y means: where <timepart> mod y = x
or
#Scedule(cron="0 0 3,7,11,15,19,21 * * ?")
According to the Quartz Cron Trigger Tutorial:
The '/' character can be used to specify increments to values. For
example, if you put '0/15' in the Minutes field, it means 'every 15th
minute of the hour, starting at minute zero'. If you used '3/20' in
the Minutes field, it would mean 'every 20th minute of the hour,
starting at minute three' - or in other words it is the same as
specifying '3,23,43' in the Minutes field. Note the subtlety that
"/35" does *not mean "every 35 minutes" - it mean "every 35th minute
of the hour, starting at minute zero" - or in other words the same as
specifying '0,35'.
0 0 3,7,11,15,19,23 * * ?
Fires for 0 minute starting at 3am and ending at 23:00 pm every day.
judging by the two answers above the error i was making was i was keeping the apostrophe at the start and end of my hours... very silly
i managed to solve this by using 3-23/4 for the hour as this starts from 3am and then every other fourth hour (just a different way of doing it to the other answers)
Does anybody know formula ?
I tried following:
1000 / ((BPM * 24) / 60).
But seems not correct.
I don't think my answer is MIDI-specific, but to convert beats-per-minute to ms-per-beat, would this work?
ms_per_beat = 1000 * 60 / bpm
In other words, I think you have an extra "24" in there.
It is simply:
Time of 1 beat in ms = 1000 * 60 / BPM = 60000 / BPM
It looks like your formula is assuming data coming from a standard midi file, where tempo is expressed in terms of ticks, where there are 24 ticks per quarter note. It's not giving you ms per beat, it's giving you ms per tick.
I wrote an article on converting BPM to MS
and I made an online app called a Delay Time Calculator that does just that including giving you dotted and triplet notes