Multi-Core Support in Gyroscope October 16, 2020

View all articles from Gyroscope Development Blog

Starting 17.1, a specific, yet common kind of functions in Gyroscope can be called asynchronously. What's more, it takes little coding change to take advantage of multiple CPU cores on the same host, or multiple hosts across the network.

Initially, this experimental component, code named "GSX", was developed to reduce the first load time of an LCHH page.

Consider a typical dashboard page where there are many panels. Each panel contains a sub view that can be updated without refreshing the rest of the page. A conventional approach to building such a dashboard is to return empty containers. Additional requests are then initiated by the browser. The end result is a sub-optimal user experience that we call a Spinning Galore:

The very design of LCHH prevents the above scenario. The content inside each container is rendered and returned in response to the very first web request. There is no extra round trips and last minute DOM changes. The dashboard is instantly populated with content, ready to go.

When there is a high number of sub views, the server-side loading time adds up. There are scenarios where client-side loading is not suitable. For example, in the case of a long document, the sub views are part of a master view. Knowing that all the DOM elements are in place once the main page is loaded gives a level of simplicity and robustness.

Consider the serial rendering of the above document:

show_one('a',123);

show_two('x','y');

show_three();

show_four('abcd');

Mark the function calls that need to be computed in parallel but still output serially:

gsx_begin();

gsx_exec('show_one',array('p1','p2'),'a',123);

gsx_exec('show_two',array('x','y'),'a',123);

gsx_exec('show_three',array(),'a',123);

gsx_exec('show_four',array('str'),'a',123);

gsx_end();

This will engage all the CPU cores:

Out of the box, 17.1 comes with a GSX demo. Look for the keyword "gsx" and enable the commented out lines in the following files:

  • myservices.php
  • icl/gsx_hello.inc.php
  • icl/showwelcome.inc.php

In addition, change lb.php and point the GSX_SERVERS location to the public URI of the Gyroscope instance. For example "https://xyz.com/admin/myservices.php"

gsx_hello is called repeatedly to print out some simple text. In addition it also calls password_hash (BCrypt) to perform some intensive calculation.

Once the code is GSX enabled, there is a single switch in lb.php to turn GSX off without changing the code back. When GSX is switched on, all the CPU cores are fully utilized:

In comparison:

For a function to be GSX compliant, it must have a switch entry in myservices.php. In addition, the function arguments must accept both the direct call stack and URL query parameters. For example:

function showorders($productid=null){

    if (!isset($productid)) $productid=QETVAL('productid');

}

GSX translates all the call stack arguments to $_POST parameters. Existing $_GET parameters are forwarded.

It is possible to intercept the return values at the end of a GSX batch:

function showorders($productid=null){

    if (!isset($productid)) $productid=QETVAL('productid');

    $extradata=array(...);

    gsx_return($extradata);

}

...

gsx_begin();

gsx_exec('showorders', array('productid'), 123);

$res=gsx_end(); //all the returned values are captured here

Our Services

Targeted Crawlers

Crawlers for content extraction, restoration and competitive intelligence gathering.

Learn More

Gyroscope™ ERP Solutions

Fully integrated enterprise solutions for rapid and steady growth.

Learn More

E-Commerce

Self-updating websites with product catalog and payment processing.

Learn More