KB Processing
All KB processing occurs by G2 performing a set of tasks within a continuous main processing cycle. The scheduler is a part of the main processing cycle.
The main processing cycle is constantly active as long as G2 is running as a process on your system. For instance, when you first start G2, it is the processing cycle that enables G2 to respond to a mouse click in the background area and display the Main Menu. In G2, a mouse click is a user interface request, one of the requests that the processing cycle services continuously.
Ticking the G2 Clock
Tasks are time-related, they are either executing currently or awaiting execution at a future time. For G2 processing, time passes according to the G2 clock.
A clock tick is the fundamental unit of time within G2. The scheduler advances the G2 clock and, between every clock tick, completes tasks scheduled for that particular time segment.
Caution: The G2 clock has a limit of 17 calendar years. Reaching that limit, for example when using the as fast as possible mode for simulation purposes, will abort G2.
The G2 Simulator is a superseded capability. For more information, see Appendix F, Superseded Practices.
The Minimum-scheduling-interval attribute of the Timing Parameters system table determines the interval between the scheduling of each clock tick. The value of the attribute is either a specific time interval (which can be more or less than a second), or continuous.
Within the main processing cycle, the scheduler constantly checks to see if it is time to tick the G2 clock. If it is not time to tick, the scheduler continues processing any outstanding tasks in the task queue. If it is time, the scheduler ticks the G2 clock and continues the subsequent tasks in the processing cycle.
The G2 clock is completely separate from the computer's system clock, known as the real-time clock, even though both may be set to the same time and advance at the same rate as the real-time clock.
Scheduling and Prioritizing Tasks
The scheduler works with tasks, which are the smallest units of activity that G2 performs. Virtually all processing within a knowledge base (KB) is executed as a task, whether G2 is displaying an attribute table, getting a value for a variable, or evaluating an expression. Tasks are scheduled or unscheduled and, if scheduled, include a priority.
Note: Certain KB functions, such as advancing the G2 clock, servicing underlying network requests, or responding to user interface requests, occur within each processing cycle. Such core tasks cannot be scheduled: they are processed continually and automatically.
Task Queues
As scheduled tasks are created within a KB, the scheduler places them in one of two queues, the future task queue and the current task queue, ordering each task according to its priority and time of execution.
The current task queue contains tasks currently eligible for execution. Once a task completes, the scheduler removes it from the current task queue. If the scheduler is unable to perform all of the tasks in the current task queue within a single clock tick, it defers the remaining tasks to the next clock tick, again sorting the tasks according to their priority.
The future task queue is a queue of time queues. Each time queue contains tasks that are eligible for execution at a future time. For tasks with continual updates, such as a variable that requires updating every 2 seconds, one update task is scheduled at a time. When the scheduled update task is complete, another is scheduled for a future time queue 2 seconds hence, and so on.
The number of future time queues is limited by the scheduling interval. For example, if the KB is using a 1 second scheduling interval, no more than one future time queue per second can exist for each second during which KB tasks are scheduled.
Following is a conceptual diagram of the task and time queues, using a one-second scheduling interval.

|
The future time queues extend to the task scheduled furthest from the current task. For example, if a you set a variable to update every five minutes, and this is the scheduled task furthest from the current task, the future time queue for tasks five-minutes from current processing marks the last queue in the future task queue.
Prioritizing Tasks
Every task has an associated priority that indicates its relative importance, and which the scheduler uses for determining its position in the current and future task queues. When the scheduler places tasks onto the current task queue, it sorts the tasks by priority; scheduling priority 1 tasks first, priority 2 tasks second, and so on.
Some tasks have set priorities that you cannot change. For example, during activation, G2 invokes and completes all initially rules, effectively delaying scanned rules until it completes every initially rule. Rules have a default priority of 6, set in the rule's Rule-priority attribute, which you can change.
Default Task Priorities
The default priorities of some common G2 tasks are:
|
Task
|
Priority
|
Comments
|
|---|
Action and update buttons
|
2
|
Includes radio buttons, check boxes, type-in boxes, and sliders.
|
Remove or unhighlight messages
|
2
|
|
Update displays (readout tables, meters, dials, graphs, trend-charts, charts, and freeform-tables)
Graphs are a superseded capability. For more information, see Appendix F, Superseded Practices.
|
2
|
Updating screen displays consists of two parts. First, the value of the display is found; second, the screen display is changed. You can override the default in an individual display's attribute table.
|
Complete data service
|
4
|
When G2 cannot receive all of the values from a data server in the time that is allotted, the scheduler schedules a task to finish reading that data. This task has priority 4. You can change this priority with the Priority-of-data-service option in the Data Server Parameters system table.
|
Update variable values
|
4
|
Variable values are obtained through backward chaining and other data-seeking.
|
Invoke rules
|
6
|
You can set an individual rule's priority in its attribute table.
|
Start procedures
|
6
|
You can set a procedure's priority in its attribute table.
|
Reply to outside requests for data from G2
|
6
|
|
Detect variable failure, and retry variables
|
8
|
For a description of failed variables, see Handling a Variable Failure.
|
Drawing and printing
|
8
|
You can change the printing priority using the Printing-priority attribute of the Printer Setup system table. There is no way to change drawing priority.
|
KB Save operation
|
8
|
The priority for saving a KB using the KB Save option on the Main Menu. The priority
|
The scheduling priority 8 is considered a background process. Whenever tasks are scheduled at a higher level priority, such as rules and procedures, background tasks with a priority level of 8 proceed slowly.
Main Processing Cycle
These are the six major events that occur during each processing cycle. Shaded events are those that the scheduler completes.
Copyright © 1997 Gensym Corporation, Inc.