Announcing New Open Source Libraries: Cronus and Hermes

cronus-hermes
We are pleased to announce that we have open-sourced two additional AddThis libraries. Cronus is a lightweight cron Java library. Hermes is a programmable page speed measurement tool. The libraries have been released under the Apache License 2.0.

Cronus

Cronus accepts Vixie Cron syntax and schedules actions for execution. The cronus implementation is relatively small at under 5,000 lines of code. Much of its functionality relies on the excellent JSR 310 library in Java 8 to perform date/time calculations.

One feature of Cronus that distinguishes it from other Java scheduling libraries is its ability to compute both the next and previous times for an action. To compute the next or previous time for an action, the date and time are first calculated in a LocalDateTime environment, which is a calendar system that ignores time zones. Then the calculated local date time is translated into ZonedDateTime environment. Vixie Cron semantics are applied for handling daylight savings times in the pre-processing conversion of the input time from a zoned date time to a local date time and the post-processing conversion from a zoned date time to a local date time.
Computing the next time in a local date time environment is relatively straightforward. We begin with a case analysis: either the cron pattern is potentially a match to the current date or it is definitely not a match. If the current date is a potential match then we compute the minutes and hours in O(1) time (see CronPattern#nextSameDay() for details). If either the current date is definitely not a match or if no matching minutes and hours could be found in our first step, then minute and hours are set to their earliest matches values. To compute a matching day, we fall back to iterating through the days. The brute force approach was simpler than devising an algorithm to account for both the [Month, Day of Month] and [Day of Week] constraints and the cost of iterating through days is acceptable. Computing the previous matching time uses the same approach as the next matching time.
Here is a contrived example of using the Cronus library. Uninterruptibles is from the Google Guava library.
public static void main(String[] args) throws Exception {
  CronScheduler scheduler = new CronScheduler.Builder(1).build();
  Future<?> future = scheduler.schedule(CronPattern.build("* * * * *"),
    () -> System.out.println("hello world"), false);
  scheduler.start();
  for(int i = 0; i < 70; i++) {
    Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
    System.out.print(i + " ");
  }
  future.cancel(false);
  for(int i = 0; i < 50; i++) {
    Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
    System.out.print(i + " ");
  }
  System.out.println();
  scheduler.stop();
}

Hermes

Hermes PageSpeed is a library and application for performance measuring of website load time. Its distinguishing features are twofold: it is programmable using the Selenium framework and it conducts repeated experiments to determine statistically significant results.
There are many good performance measurement tools available online. Several popular sites include Google’s PageSpeed Insights, Yahoo’s YSlow, and WebPageTest. Hermes allows you to measure site performance if you need to perform some kind of action in order to get to the page you want to measure, such as providing a username and password. The application performs multiple iterations of the experiment so that summary statistics for each measurement are generated.
Hermes uses the Selenium browser automation framework to allow actions to be scripted prior to recording page loading times. A default class is provided to simply load a webpage if no complex actions are required. Hermes also relies on the Chrome browser Navigation Timing and Resource Timing APIs to record page load statistics. The current Hermes implementation only has support for the Chrome browser and uses the ChromeDriver library to control the browser.
What is generated is a series of observations on page load timings with repeated identical experiments so that the statistical significance of the measurements can be determined. A simple python script has been included in the git repository for converting the json output into a series of graphs. You can either run the main application directly or use the Main class as a starting point for writing your own custom workflow. Here are some sample graphs generated for the Space Jam homepage.
The startTime of page resources.
Start Time
The responseEnd of page resources.
End Time
The elapsed time of resource loads as calculated by (responseEnd – startTime).
Duration
The legend for previous three graphs.
Legend
Measurements from the Navigation Timing API.
Navigation Timing API

0 comments:

Post a Comment