On my first month at Microsoft, I filed a valuable patent (US10931784B2). I sized it that way since one year later, AWS and GCP already implemented the idea. It sounds illegal. I think it is Microsoft business though. I am innovator, this is my playground!
I remember this very day, I was presenting my design for a new project to a principal engineer. After I finished, there was a moment of silence. I know it was a draft, I worked hard on it since all I have in mind was to prove myself as a new employee. Nevertheless, I was open to rethink all my work. For the sake of becoming better. Then he broke the silence with a question. Voila! it just triggered the innovation spirit in me.
“I am not sure about the azure functions periodic events approach…”. He paused, turned back to me, and continued, “It is not our best practice in the department, no one else tried it. It may break in peaks…“.
I wanted to use the serverless azure function to crawl data on a periodic basis. However, The problem is that computing tier can be expensive with a timer trigger. if the client is flexible with the execution time, it is possible to use the lazy timer in order to save additional costs by minimizing the scaling out.
The idea behind this flexibility is to start the execution in a near-optimal time while sticking to the constraints of the schedule, with the purpose of minimizing heavy loads magnitude and duration due to overlapping executions.
High load peaks could result in scaling out the computing instance which will cost the cloud customer and the cloud provider more money. Utilizing the current computing power accordingly without wasting additional resources due to stringent usage would benefit both the customer and the provider.
The Lazy Function niche
The lazy function comes in handy for users that are flexible with regard to the exact timing of execution in a given interval. For example, a cloud service that runs once every minute/hour may be willing to deviate from the exact time by 5 seconds/minutes.
Let’s assume that we have a cloud function which runs every T seconds. The azure function execution takes more than T seconds to finish. Let’s also assume it takes 1.2T seconds to finish.
If the first execution started at t=0, then, according to the regular time triggered function, the second execution starts at t=T. Therefore, we would expect a high peak at t=T as we have two instances that are running simultaneously with overlapping executions. If the user is flexible regarding the start of the execution, then it would be optimal to start the execution of the second scheduled cloud function on t= 1.2T+ε as the load would be lower.
The lazy time triggered function can be configured by the customer to execute with an interval of T seconds between every two executions and some deviation at each execution. The deviation can either be defined additively (i.e., T ± Δ, where Δ > 0) or multiplicatively (i.e. (1 ± α)T, where α > 0).
Choosing the point in time within the defined permitted time period, in which a function should start execution, aims to minimize the overall magnitude and duration of heavy loads. We present two methods by which this can be accomplished.
Based on a predefined probability distribution function
We define a probability distribution function that assigns a probability to whether to start the execution in any permitted point in time based on the improvement in load. This probability distribution is defined between T- Δ and T+ Δ, such that for any percentage of improvement from the load at T- Δ, it assigns a probability of starting the execution. This function should assign the probability 1 at T+ Δ. The following figure shows examples of such functions: