Informatica 35 (2011) 269-282 269 Real-Time Action Scheduling in Pervasive Computing Wenwei Xue Nokia Research Center, Beijing, China E-mail: wayne.xue@nokia.com Qiong Luo and Lionel M. Ni Department of Computer Science and Engineering Hong Kong University of Science and Technology Clear Water Bay, Kowloon, Hong Kong, China E-mail: {luo, ni}@cse.ust.hk Keywords: pervasive computing, real-time action scheduling, query processing, device eligibility Received: November 23, 2010 Pervasive computing applications, such as video surveillance and robot control, involve diversified operations on physical devices. We call a sequence of operations on a device an action and study how to schedule real-time actions on the devices in pervasive computing. We identify a number of novel characteristics of this pervasive action scheduling problem and develop a dynamic, heuristic algorithm for the problem. The algorithm performs priority-based action scheduling whenever some device becomes free and does not reply on any system-defined scheduling interval. We have implemented our proposed action scheduling algorithm in a pervasive query processing system named Aorta and evaluated its performance using actions in a pervasive lab monitoring application. Our simulation results demonstrate the algorithm ensures small dropping rate of actions and has tiny computation cost. Povzetek: Opisan je izvirni sistem Aorta, kjer je akcija opisana kotpovprasevalni operator. 1 Introduction In pervasive computing [27], many types of devices are embedded in the physical world and execute real-time actions for the applications [22] [24], Example devices in pervasive computing include sensor nodes, network cameras, programmable robots, and handheld devices such as PDAs and phones. Here we define an action as a predefined sequence of operations to be executed on a device that is encapsulated in a user-defined function [1][8], Due to the real-time requirement of action executions, action scheduling on the devices among multiple applications is a crucial problem in pervasive computing. For instance, in a lab surveillance scenario a number of concurrent applications may require the cameras and robots deployed in the lab to take photos or perform tasks at different locations from time to time. A photo taken or a task performed will become obsolete and useless if it cannot be scheduled and executed timely on some device of the corresponding type. In this paper, we address this action scheduling problem in the framework of a pervasive query processing system Aorta that we have developed [29] [30], The problem of job scheduling on parallel machines [16] and its variants [3][5][11][13][17][18][19][20][23] [25] [26] have been widely investigated in the literature. The action scheduling problem we study can be regarded as a new variant of this classic problem in the pervasive computing scenario. This is because an action execution for an application is often not fixed to a specific device but can be performed on any device that satisfies certain condition. Take the lab surveillance scenario as example again. Whenever a sensor node installed in the lab detects abnormally high noise readings lasting a period, which are likely caused by the loud conversation of people around the node, a robot is automatically controlled to move to the location of the node and issue a warning to ensure the quiet working environment in the lab. Every robot in the lab is a candidate device for this action execution and it is sufficient to operate one but not all of them to perform the task. Our action scheduling problem inherits several characteristics of the classic parallel machine scheduling problem, including unrelated devices, device eligibility restrictions and deadlines of non-preemptive action executions [16], In addition, our problem has a unique characteristic that is the interaction between actions and devices [29] in pervasive computing. More specifically, the actions often change the physical status of the devices that execute them. Such change in turn affects the future executions of succeeding actions on the devices. The physical status of a device is represented in Aorta as the current values of a set of status attributes defined in the virtual table for the type of device [30], Example status attributes in different virtual device tables are voltage, freeRAM for sensors and phones', pan, tilt, zoom for cameras', loc, angle for robots. 270 Informatica 35 (2011 ) 269-282 W. Xue et al. CREATE AQ noiserejection AS SELECT warn(r.id, s.loc, "messages/warning.txt") FROM sensors s, robots r WHERE 600 < (SELECT \vinavg(ss.noise. 5, 5, minute) FROM sensors ss WHERE every(10, second) AND ss.id = s.id) DEADLINE 30 seconds Figure 1: The noise rejection query for lab surveillance. Figure 2: Devices in the pervasive lab. The scheduling model we face in our problem is dynamic rather than the static model adopted in the classic problem. The action executions to be scheduled on the devices are dynamically arriving at the system over time. In contrast, the classic problem takes a static set of jobs as input and assumes all kinds of job information, e.g., the start or processing times of the jobs, are known a priori before the scheduling [16], We summarize all these characteristics of our action scheduling problem and propose a dynamic, heuristic algorithm to solve the problem. Whenever a device becomes free, the algoritlun selects an action request queued in the system that has the highest priority to be serviced on the device. We define an action request as the request for an action execution from an application with instantiated values for the input parameters of the action. The priority of an action request on a device is computed using the response time of the request on the device, the deadline and the candidate device number of the request, as well as the current eligibility and reliability of the device. We have implemented the algorithm in our Aorta prototype and seamlessly integrated it with other mechanisms in the system [30], The effectiveness of declarative queries to task networks of devices has been illustrated by lots of recent work in both database [12] [31] and networking [10] [21] communities. Following this programming paradigm. Aorta uses SQL-based continuous queries having actions embedded [29] to express the processing logics of pervasive computing applications. We call these queries action-embedded queries. With this abstraction for applications, the process of action scheduling in Aorta is encapsulated into the adaptive group optimization of multiple concurrent queries running in the system. Although in this paper we present and evaluate our action scheduling algoritlun based on these system implementation details of Aorta, the algoritlun is generic and is indifferent to the particular application interface. We have designed the syntax and semantics of action-embedded queries to accord with the requirements of action scheduling. An optional DEADLINE clause is provided in Aorta's query interface for applications to tell the system the deadline of an action request from a query, which is defined as the interval between the time when the request is issued and the time when the request is serviced on a device (i.e., the action execution has been finished). Moreover, when the WHERE clause of an action-embedded query is evaluated as true and a set of candidate devices is determined for the action request, the request will be scheduled and serviced only once on a selected device among these candidates [29], As an example, Figure 1 shows a noise rejection query in Aorta that abstracts the robot patrol application for lab surveillance we have described previously. We have built a case study application on our Aorta prototype to monitor the pervasive research lab in our department. The lab is equipped with desktops having removable hard disks, notebooks, and various types of devices including Crossbow motes [4], AXIS 2130 network cameras [2], ER1 personal robots [6], PDAs and phones (Figure 2). This pervasive lab monitoring application is used as an illustrative example throughout the paper as well as in our performance evaluation of the proposed action scheduling algoritlun. The remainder of this paper is organized as follows. We describe the Aorta system model for action scheduling in Section 2. We identify the characteristics of our action scheduling problem in Section 3 and present a dynamic, heuristic algorithm for the problem in Section 4. In Section 5, we perform simulation studies to evaluate the effectiveness of our proposed scheduling algoritlun using actions in the pervasive lab monitoring application. REAL-TIME ACTION SCHEDULING IN. Informatica 35 (2011 ) 269-282 271 We discuss related work in Section 6 and conclude the paper in Section 7. 2 System model for action scheduling In this section, we describe the model we implement in the Aorta system to effectively support the action scheduling on devices. 2.1 Actions and action operators Aorta only supports actions that operate a single device. We focus our study on single- device actions due to three main reasons: (i) they are prevalent in real-world applications [1][8][22][24], (ii) they are more practical and manageable in implementation, and (iii) in combination with action or query nesting, they can be used to compose many multi-device actions that have simple communication logics between devices [29], For every action in Aorta, we require the identity of the device that the action is executed on to be not fixed in the function code block. In contrast, the device should be explicitly or implicitly identified by the instantiated parameter values for the action at run time. As a typical example, the first input parameter of the warn action in Figure 1 determines the robot on which a specific execution of the action will be executed. The necessity of this restriction stems from the "black box" nature of actions. Being a UDF, an action is registered to Aorta as a compiled code block and it is impossible for the system to modify its implementation details. Consequently, if the identity of the device to execute an action is fixed in the code block, there is little room for action scheduling on the parallel devices. In this case, our problem degenerates to a single-machine scheduling problem [16] on individual devices. Aorta makes an action embedded in a query a first-class operator in the evaluation plan of the query. An action operator contains the following information about an action: (i) the name, (ii) the specifications of input parameters, (iii) the pointer to the function code block to be invoked. Furthermore, all queries having an action on the same type of device share a single action operator among their query plans. Every query plan is connected to the shared action operator via a common input queue of the operator. The action operator maintains corresponding information about the action embedded in each query so that it can use the correct information to schedule a specific execution of an action for a query. An action operator is created when the first query embedded with an action on the type of device is registered to Aorta. Subsequent queries having actions on the same type of device are connected to the operator by an update of the information maintained in the operator. These shared action operators give the Aorta query optimizer a global view of the current action workload on individual types of devices in the system. Rather than being optimized separately without coordination, multiple queries are grouped and the action executions for them are adaptively scheduled as a whole. 2.2 Scheduling model Figure 3 depicts the scheduling model for every action operator in Aorta's query processing framework. In the figure, dj (1 < j < m) denotes all devices of a type involved in the Aorta system that the operator is in charge of action scheduling on, e.g., the set of programmable robots. <7,- (1 < /' < n) denotes the plan of Query /' and R, the streaming action requests issued from the query over time. R denotes the whole stream of action requests that arrive n at the input queue of the action operator and R = |J R,. i=i Being the main component of the operator, the scheduler implements the dynamic and heuristic action scheduling algorithm we have developed, a, (1 < / < n) in the operator denotes the stored specification information about the action that is embedded in Query /'. 3 Characteristics of action scheduling The action scheduling problem we study has a unique set of characteristics that is tightly related to the application scenario of pervasive computing. We identify all characteristics of the problem one by one as follows. (1) Action-device interaction. There is a special kind of interaction between actions and devices in pervasive computing: an action execution on a device may change the physical status of the device; in turn, the physical status of a device may affect the cost of an action execution on the device. This interaction is generic to several cost metrics for actions in pervasive computing, such as the response time, the power consumption and the price of service. It makes our scheduling of actions more complex than traditional job scheduling, because the costs of an action execution on candidate devices are different and dynamically changing. Pi q2 qn Input Queue Action Operator Scheduler a1 a2 an J" Figure 3: Scheduling model for an action operator in Aorta. 272 Informatica 35 (2011 ) 269-282 W. Xue et al. Figure 4: The snapshot queiy in the pervasive lab monitoring application. CREATE AQ snapshot AS SELECT photo(c.ip, s.loc, "photos/admin") FROM sensors s, cameras c WHERE s.accel x > 500 AND coverage(c.loc, s.loc) To illustrate the interaction, two actions in the pervasive lab monitoring application are listed in Examples 1 and 2. The device physical status related to the action is the location of a robot or the head position of a camera, respectively. Example 1. Consider the warn(id, location, text Jile) action Figure 1 on programmable robots [6], The action operates a robot with id to rotate towards and go straight to a target location, and play a warning message whose content is specified in text Jile when arriving at the location. An execution of the action changes the location of the robot. The response time of the execution is proportional to the distance between the target location and the current location of the robot. ■ Example 2. Consider the photo(ip, location, directory) action in Fig on PTZ network cameras [2], The action operates a camera with ip to move its head to a position pointing at location and take a photo. The action then stores the photo that the camera takes to directory. An execution of the action changes the position of the camera head (i.e., the pan, tilt, zoom values). The response time of the action execution depends on the current head position of the camera. ■ (2) Dynamic request arrival in a global queue. Action requests from multiple queries continually and dynamically arrive at the single input queue of an action operator over time. There is no local request queue for a device. The system has no prior knowledge about the arrival time, deadline or candidate devices of each request. (3) Deadlines of requests. Action executions are of little use for pervasive computing applications if they cannot be finished in a timely manner. An unscheduled action request should be dropped when the system detects that the request cannot be serviced within its deadline. (4) Independent and non-preemptive requests. There is no message communication between any two action requests as they represent separate executions of actions. Since the execution flows of actions are encapsulated in code blocks and are unknown to the system, an action execution on a device cannot be interrupted and multiple executions cannot be interleaved on a device. As a result, no communication is required in the scheduling to transplant a partially-serviced action request from one device to another. (5) Unrelated devices. The cost of an action request on a device is generally not related to those costs of the request on the other devices. In other words, the devices in our action scheduling model are unrelated [16], Each device services the action requests scheduled on it individually. (6) Device eligibility. The candidate devices for an action request often include a subset of all devices of the type in the system. For instance, for the snapshot query in Figure 4, the set of candidate devices for a request is determined by the function coverage(loc\, loci) in the queiy condition. The function returns true if and only if the view range of the camera with location loci covers the location loci. This example also indicates the fact that the set of candidate devices for multiple action requests of the same query may be different. We say that a device is eligible for an action request if it is a candidate for servicing the request. The last four characteristics of our problem can be mapped to the following characteristics of the classic parallel machine scheduling problem [16] in order: (i) deadlines of jobs, (ii) non-preemptive jobs, (iii) unrelated machines, and (iv) machine eligibility restrictions for jobs. Moreover, the first characteristic of our problem is similar to the sequence-dependent setup time of jobs in the classic problem [16], The major difference is that we are facing sequence-dependent response time (in general, cost) of action requests rather than setup time. To the best of our knowledge, there is no existing scheduling algorithm for the classic problem or for any variant of it whose design has taken all the characteristics (i)-(iv) and the sequence-dependent setup time into consideration. The second and third characteristics of our problem require us to adopt a dynamic model [11] [17] for action scheduling rather than the static model in the classic problem [3][16], In our previous work, we have developed two non-real time algorithms for action scheduling in Aorta without considering the request deadlines [29] [30], The algorithms are based on a static scheduling model that divides the system time into a sequence of equal-length scheduling intervals and schedules action requests arriving in each interval individually. However, in our subsequent real testbed evaluation of Aorta, we found that these prior algorithms have a major drawback when applying to the scheduling of actions with deadlines, that is, their performance in practice largely depends on the length of the system-defined scheduling interval. If the interval is long, requests that arrive earlier in an interval suffers from a large delay and their deadlines are more likely to be missed, whereas veiy few requests can be scheduled together in each interval and the static group scheduling becomes less effective if the interval is short. With a dynamic scheduling model, it has been proved that if we do not assume any prior knowledge about the arrival times of the continuously-arriving jobs, an opti- REAL-TIME ACTION SCHEDULING IN. Informatica 35 (2011 ) 269-282 273 mal algorithm does not theoretically exist for a job scheduling problem [5], In comparison, a static model makes the design of an optimal scheduling possible as all kinds of information about the jobs in a scheduling interval is available before the scheduling starts. Nevertheless, such static scheduling problem is NP-hard and too computationally expensive to be feasible in our real-time scenario [30], Even a sub-optimal, non-heuristic solution for the problem, such as the Simulated Annealing (SA) algorithm we have studied before [30], requires large computation cost given a small input size. As a summary, the unique set of characteristics of our action scheduling problem in pervasive computing makes scheduling algorithms in the literature based on a static model inapplicable to the problem, due to their significant running time or unconcern for a few characteristics. These negative observations, as well as the effectiveness of our prior static heuristic algorithms for non-real time action scheduling [30], motivate us to propose a new dynamic, heuristic algorithm for the real-time action scheduling in Aorta. 4 Heuristic scheduling algorithm We present the detailed design of our heuristic algorithm for real-time action scheduling in this section. Algorithm 1 formulates the input and output of the problem and depicts the flow of our proposed algorithm. The algorithm is called by an action operator immediately after the operator is generated. We developed the algorithm based on the List Scheduling (LS) discipline in scheduling theory [16] due to the tiny algorithmic running time incurred by the discipline. Whenever a device becomes free, the LS discipline schedules a request in the queue that the device is eligible for on the device using a heuristic. Algorithm 1 starts by initializing the status information about all devices involved in the scheduling (Lines 13). Such information is dynamically maintained during the execution flow of the algorithm (Lines 10, 19). The algorithm then enters an endless scheduling loop (Line 4) and performs action scheduling on the devices round by round. The loop stops only when the system is terminated and the action operator is destroyed. In each round of the scheduling loop, Algorithm 1 first examines all requests in the input queue of the action operator and removes those requests whose deadlines have been missed at this time (Lines 5-6). Next, for each device that is currently free, the algorithm computes the priority (PRL value) of every request in the queue that the device is eligible for using Function computePriority (Line 14). Function estimateCost(ru dj, M) estimates the current cost of request r, on device dj based on a cost model M (Line 12). The algorithm then selects the request-device pair (rs. ds) having the highest priority (Lines 15-16) and schedules request rs on device d, in this round (Line 18). Note that we regard a request-device pair has a higher priority if the PRL value of this pair is smaller. Algorithm 1: Dynamic and Heuristic Action Scheduling_ Input: An action operator P on a type of device and the set of all m devices of the type I) = (c/,. d2,. ..,dm). The streaming action requests R = (r,. r2. .... r„. ...) appear in the input queue of P. Each r, e R has a deadline /J/., and a set of candidate devices Di e I). Output: A schedule of 'R on I). Each r, e R is either assigned to and serviced by a device d e Dh or is dropped due to the missing of its deadline. 1: for each device d, e D (1 = DL,) then remove r, from R; /* r, is dropped due to the missing of its deadline */ 7: rs = null; ds=null; PRLs = + inf; /* request rs is to be scheduled on device ds in this round */ 8: for each device di e I) do 9: if d,.nextFreeTime > Snow then continue; /* di is currently busy */ 10: d,.nextFreeTime = Snow; update the new physical status of d{, 11: for each action request r, in R with d, e D, do 12: costy = estimateCost(rh dh M); I*Mis the cost model used to estimate the cost of r, on <:/, */ 13: if (Snow + costi4>DLt) then continue; /* deadline of r, cannot be caught one/, at this time */ 14: PRLy = computePriority(rh d), costy); 15: if PRLy < PRIS then 16: rs = r;, d,= df- PRIS = PRL„; 17: if PRI, != + inf then 18: remove r. from R and service it on ds; 19: ds.nextFreeTime = Snow + the cost of servicing rs on ds; 20: if Snow < min{d,.nextFreeTime} (1