How is delay of the akka scheduler? - scala

I wrote an actor, using a scheduler each 5 milliseconds to assign a time stamp to a field.
And in test, I found that the result of (System.currentTimeMillis() - timeField) is at least 35
And if I use a scheduleAtFixedRate() method from the Executors.scheduledThreadPool, the result is right.
So is the scheduler delay has a min value ?
Answer: the default tick duration is 100 milliseconds.

ScheduledThreadPoolExecutor uses System.nanoTime():
http://fuseyism.com/classpath/doc/java/util/concurrent/ScheduledThreadPoolExecutor-source.html
See comparison here:
System.currentTimeMillis vs System.nanoTime

Akka has a fairly extensive documentation.
Here's an excerpt:
"The default implementation of Scheduler used by Akka is based on the Netty HashedWheelTimer. It does not execute tasks at the exact time, but on every tick, it will run everything that is overdue. The accuracy of the default Scheduler can be modified by the “ticks-per-wheel” and “tick-duration” configuration properties. For more information, see: HashedWheelTimers."

Related

How is the HDL simulation timeout specified when using OpenCPI?

My simulation fails to stop until an inbuilt timeout is reached. The default is 3600 seconds. How do I set this to a different time period?
The openCPI version is 2.4.3.
Any suggestions?
This is my first use of OpenCPI.
You can change the default timeout for tests using the Timeout attribute in the Tests element of your test XML like below:
<Tests UseHdlFileIO="true" Timeout="30">
<Case>
<!-- Inputs and Outputs in here -->
</Case>
</Tests>
The timeout is defined in seconds. More information can be found in section 13.3.5 of the OpenCPI Component Development Guide

Kafka Streams - time window close delay?

I'm new to Kafka Streams.
I use the suppress method of KTable in order to handle only the final result of a window like this:
myStream
.windowedBy(TimeWindows.of(Duration.ofSeconds(10)).grace(Duration.ofMillis(500)))
.aggregate(new Aggregation(),
(k, v, a) -> a, // Disabled the actual aggregation in order to eliminate possiblities of latency
materialized.withLoggingDisabled())
.suppress(untilWindowCloses(Suppressed.BufferConfig.unbounded()))
.toStream().peek((k, v) -> log.info("delay " + (System.currentTimeMillis() - k.window().endTime().toEpochMilli())));
This way I get a log with the delay every 10 seconds with the difference between the window end and the actual time the peek was called.
I would exect a very small number here, since this code practically does nothing...
Nevertheless, I get delay of 4-20 sec for each key/window.
I use a thread per task (5 threads for this topic).
Can someone please point out if I'm doing anything wrong?
Thanks!
Edit:
Using VirtualVM shows that ~99% of the time consumed over sun.nio.ch.SelectorImpl.select(). This means AFAIU, that the process is "idle" most of the time.
Edit:
It seems that changing "commit.interval.ms" (which was by default 30000) reduced the delay drastically.
Still delay has peaks of event 15 seconds, so the problem isn't solved yet...

Sahi scripting wait or time delay

I was wondering if someone could help me. I want to introduce a 10 minute wait or time delay within my sahi script.
Can someone confirm the correct command to use?
Thanks in advance
Just have a look at the docs, the command you are looking for is _wait
https://sahipro.com/docs/sahi-apis/action-apis.html#Waits
Write _wait(parameter); where parameter is your the time in milli-seconds you want to introduce the delay for.
In your case try _wait(600000);
You can also use the setSpeed(parameter); API , in this case Sahi will wait for the time specified in milli-seconds as a parameter , after each task in the script. But I guess waiting 10 mins after each task is not your requirement.
You can use this method:
_wait($timeout, [$condition])
here $timeout is the duration you want to wait for. And $Condition is something that you can customize based on what condition you want to wait for.
Or you can just use the overloaded method _wait($timeout) if you want to wait for a specific duration.
You can also apply a conditional wait:
_wait(timeOut, _isVisible($element));
This will either wait till "timeOut" milliseconds, or till $element is visible. (whichever condition is satisfied earlier)

Setting Time Limit on specific task with celery

I have a task in Celery that could potentially run for 10,000 seconds while operating normally. However all the rest of my tasks should be done in less than one second. How can I set a time limit for the intentionally long running task without changing the time limit on the short running tasks?
You can set task time limits (hard and/or soft) either while defining a task or while calling.
from celery.exceptions import SoftTimeLimitExceeded
#celery.task(time_limit=20)
def mytask():
try:
return do_work()
except SoftTimeLimitExceeded:
cleanup_in_a_hurry()
or
mytask.apply_async(args=[], kwargs={}, time_limit=30, soft_time_limit=10)
This is an example with decorator for an specific Task and Celery 3.1.23 using soft_time_limit=10000
#task(bind=True, default_retry_delay=30, max_retries=3, soft_time_limit=10000)
def process_task(self, task_instance):
"""Task processing."""
pass

Quartz.Net - delay a simple trigger to start

I have a few jobs setup in Quartz to run at set intervals. The problem is though that when the service starts it tries to start all the jobs at once... is there a way to add a delay to each job using the .xml config?
Here are 2 job trigger examples:
<simple>
<name>ProductSaleInTrigger</name>
<group>Jobs</group>
<description>Triggers the ProductSaleIn job</description>
<misfire-instruction>SmartPolicy</misfire-instruction>
<volatile>false</volatile>
<job-name>ProductSaleIn</job-name>
<job-group>Jobs</job-group>
<repeat-count>RepeatIndefinitely</repeat-count>
<repeat-interval>86400000</repeat-interval>
</simple>
<simple>
<name>CustomersOutTrigger</name>
<group>Jobs</group>
<description>Triggers the CustomersOut job</description>
<misfire-instruction>SmartPolicy</misfire-instruction>
<volatile>false</volatile>
<job-name>CustomersOut</job-name>
<job-group>Jobs</job-group>
<repeat-count>RepeatIndefinitely</repeat-count>
<repeat-interval>43200000</repeat-interval>
</simple>
As you see there are 2 triggers, the first repeats every day, the next repeats twice a day.
My issue is that I want either the first or second job to start a few minutes after the other... (because they are both in the end, accessing the same API and I don't want to overload the request)
Is there a repeat-delay or priority property? I can't find any documentation saying so..
I know you are doing this via XML but in code you can set the StartTimeUtc to delay say 30 seconds like this...
trigger.StartTimeUtc = DateTime.UtcNow.AddSeconds(30);
This isn't exactly a perfect answer for your XML file - but via code you can use the StartAt extension method when building your trigger.
/* calculate the next time you want your job to run - in this case top of the next hour */
var hourFromNow = DateTime.UtcNow.AddHours(1);
var topOfNextHour = new DateTime(hourFromNow.Year, hourFromNow.Month, hourFromNow.Day, hourFromNow.Hour, 0, 0);
/* build your trigger and call 'StartAt' */
TriggerBuilder.Create().WithIdentity("Delayed Job").WithSimpleSchedule(x => x.WithIntervalInSeconds(60).RepeatForever()).StartAt(new DateTimeOffset(topOfNextHour))
You've probably already seen this by now, but it's possible to chain jobs, though it's not supported out of the box.
http://quartznet.sourceforge.net/faq.html#howtochainjobs