Presence servers are increasingly being used to provide presence information such as the availability status of users. Presence information identifies the current “presence state” of the user. Users make their presence information available so that other users can decide how best to communicate with them. For example, the presence information may indicate whether a user is logged on (“online”) with an instant messaging server or is logged off (“offline”). Presence information may also provide more detailed information about the availability of the user. For example, even though a user is online, that user may be away from their computer in a meeting. In such a case, the presence state may indicate “online” and “in a meeting.”
In an instant messaging context, a publishing user (“publisher”) may provide their presence information to a presence service that then provides the presence information to subscribing users (“subscribers”). Thus, a presence service may use a subscriber/publisher model to provide the presence information for the users of the presence service. Whenever the presence information of a user changes, the presence service is notified of the change by that user's computer system and in turn notifies the subscribing users of the change. A subscribing user can then decide whether to initiate an instant messaging conversation based on the presence information of the intended participants. For example, if the presence information indicates that a publishing user is currently in a conference telephone call, then the subscribing user may decide to send an instant message, rather than place a telephone call, to the publishing user. If the subscribing user, however, needs to call and speak with the publishing user, the subscribing user needs to monitor the presence information of the publishing user to know when the call can be placed. When the subscribing user notices that the publishing user's presence information indicates that the telephone conference has been concluded, the subscribing user can then place the telephone call.
Because of the increasing popularity of instant messaging systems and other real-time communication systems, presence services need to support an increasing numbers of users. To support large numbers of users, a presence service may provide a pool of front-end presence servers that are used to service the publication and subscription requests of users. Subscription and publication requests are typically routed through a load balancer of the presence service which directs the request to one of the presence servers based on the current load of the presence servers. The information of the presence service may be stored and accessed through a back-end database server, which may be a SQL server. The back-end database server may store the current presence information of each publisher, and for each publisher, store the identity of each subscriber to that publisher's presence information in database tables. When a front-end presence server receives a request, it accesses the back-end database server to respond to the request.
Various maintenance tasks need to be performed from time to time on the tables of a back-end database. For example, a subscription to the presence information of a user may expire after a certain period (e.g., eight hours). To continue subscribing to another user's presence information, a user would need to periodically re-subscribe to that other user's presence information. To ensure that tables of the database do not become filled with expired subscriptions, a maintenance task needs to be performed periodically to remove information related to expired subscriptions. More generally, in many computing environments client computer systems (e.g., front-end servers) access server computer systems (e.g., back-end database servers) that need to have maintenance tasks performed from time to time. As another example, a Session Initiation Protocol (“SIP”) registry may have a database server that maintains the registration information of registered users. Because such registrations expire, a maintenance task of removing information relating to expired registrations needs to be performed from time to time. As another example, the maintenance task may be to re-index certain tables of the database. In addition, non-maintenance tasks may need to be performed such as generating certain reports on a periodic basis, forwarding certain information to another server, uploading summary information to another computer system, and so on.
It is typically difficult to customize the back-end database server so that it can perform such maintenance tasks on its own initiative. As a result, a front-end server may be designated to perform various tasks on the database. However, when a front-end server is taken down for maintenance or fails, the tasks that the front-end server was responsible for performing will no longer be performed.
A method and system for assigning clients to tasks is provided. The assignment system includes a client component and a server component. The client component, which executes on each client, requests the server component, which executes on the server, to perform the task on its behalf. When the server component is requested to perform the task on behalf of a client, it determines whether an available client is currently assigned to that task. If an available client is not currently assigned to the task, the server component assigns an available client to the task. If the client on whose behalf the server component is executing is assigned to the task, then the server component performs the task. Otherwise, the server component does not perform the task. Because each client periodically requests the server component to perform the task, the server component will perform the task when requested by the assigned client.
This Summary is provided to introduce a selection of concepts in a simplified form that are further described below in the Detailed Description. This Summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used as an aid in determining the scope of the claimed subject matter.
A method and system for assigning clients to tasks is provided. In one embodiment, the assignment system includes a client component and a server component. The client component, which executes on each client, requests the server component, which executes on the server, to perform the task on its behalf. When the server component is requested to perform the task on behalf of a client, it determines whether an available client is currently assigned to that task. A client is available if it can request the server component to perform the task on its behalf. As an example, a client that is offline for maintenance or that has malfunctioned is not available. If an available client is not currently assigned to the task, the server component assigns an available client to the task. If the client on whose behalf the server component is executing is assigned the task, then the server component performs the task. Otherwise, the server component does not perform the task. Because each client periodically requests the server component to perform the task, the server component will perform the task when requested by the assigned client. If the assigned client becomes unavailable, the server component will assign a new available client to the task. In this way, the server component will perform the task only on behalf of the assigned client, and when the assigned client becomes unavailable, the server component will dynamically assign an available client to perform the task.
In one embodiment, the server is a database server, and the server component is a stored procedure that is invoked by the clients. The server component may include a stored procedure for each task that is to be performed at the server on behalf of a client. For example, a presence service may have a stored procedure for removing expired subscriptions, another stored procedure for removing expired registrations, and another stored procedure for re-indexing certain tables. Each client may periodically invoke each of the stored procedures to perform the tasks on its behalf. Each stored procedure may include a retrieval component for retrieving the identity of the client assigned to the task and a task component for performing the task when the client on whose behalf the stored procedure is invoked is the assigned client. When the server component is invoked, it invokes the retrieval component to determine whether an available client is currently assigned to the task. If not, the retrieval component selects an available client to assign to the task. The retrieval component may select the client that currently is assigned to the smallest number of tasks. Alternatively, the retrieval component may select a client factoring in the complexities and number of tasks to which it is assigned. Upon receiving an indication of the assigned client, the server component determines whether it is being performed on behalf of the assigned client. If so, the server component invokes the task component to perform the task. If not, the server component completes without performing the task.
In one embodiment, the server component uses a locking mechanism (e.g., a mutual exclusion mechanism) to prevent multiple invocations of a stored procedure from simultaneously accessing information needed to assign a client to a task. The server component may maintain client information indicating whether the client is available and, if so, to which tasks it is assigned. Because the clients may not coordinate the timing of their invocation of the stored procedures, it is possible that multiple clients may invoke the same stored procedure at nearly the same time. If multiple invocations of a stored procedure attempt to assign a client to the task at approximately the same time, the client information may be left in an inconsistent state. To prevent the simultaneous access of the client information by the invocations of a stored procedure, the stored procedure locks a database resource exclusively before accessing the client information and unlocks the database resource after access is complete. For example, the server component may maintain a task table that includes a row for each task which identifies the client currently assigned to the task. When the stored procedure for a task is invoked, that stored procedure attempts to exclusively lock the row for that task. If the row is currently locked, the invocation of the stored procedure will wait until the row is unlocked. If the row is currently unlocked, then the stored procedure will lock the row and continue processing. Thus, the locking of the row of a task will serialize the assigning of a client to the task by the invocations of the stored procedure for that task. The stored procedure removes the lock after the assigned client has been identified and before invoking the task component to perform the task. In this way, the client will only need to wait for a lock that spans only the assignment of a client to a task and need not wait for a lock that spans the performance of the task itself, which may take a considerable amount of time.
In one embodiment, the task assignment system uses a heartbeat mechanism to determine whether a client is available. The client component of a client may periodically send a heartbeat notification to the server. Upon receiving the heartbeat notification, the server component may record the time of the heartbeat. The server component may assume that a client is available when the last heartbeat from that client was received within a certain period. For example, the server component may assume that a client is available when the last heartbeat from that client was received within two minutes. The client component may provide the heartbeat notification to the server by periodically invoking a heartbeat stored procedure of the server. The server component may maintain a client table with a row for each client, which identifies the time that the last heartbeat notification was received from that client. When the heartbeat stored procedure is invoked on behalf of a client, it updates the last heartbeat notification time for that client in the client table. The stored procedure of the task uses the last heartbeat notification time to determine whether a client is available.
The computing device on which the assignment system is implemented may include a central processing unit, memory, input devices (e.g., keyboard and pointing devices), output devices (e.g., display devices), and storage devices (e.g., disk drives). The memory and storage devices are computer-readable media that may contain instructions that implement the assignment system. In addition, the data structures and message structures may be stored or transmitted via a data transmission medium, such as a signal on a communications link. Various communication links may be used, such as the Internet, a local area network, a wide area network, a point-to-point dial-up connection, a cell phone network, and so on.
Embodiments of the assignment system may be implemented in various operating environments that include personal computers, server computers, hand-held or laptop devices, multiprocessor systems, microprocessor-based systems, programmable consumer electronics, digital cameras, network PCs, minicomputers, mainframe computers, distributed computing environments that include any of the above systems or devices, and so on. The user devices may be cell phones, personal digital assistants, smart phones, personal computers, programmable consumer electronics, digital cameras, and so on.
The assignment system may be described in the general context of computer-executable instructions, such as program modules, executed by one or more computers or other devices. Generally, program modules include routines, programs, objects, components, data structures, and so on that perform particular tasks or implement particular abstract data types. Typically, the functionality of the program modules may be combined or distributed as desired in various embodiments.
From the foregoing, it will be appreciated that specific embodiments of the assignment system have been described herein for purposes of illustration, but that various modifications may be made without deviating from the spirit and scope of the invention. One skilled in the art will appreciate that a client is a computer system that accesses services of a server. A client may itself be a server to other clients. For example, a front-end presence server may be a client of a back-end database server and may be a server to user devices, which are clients of the front-end presence server. Accordingly, the invention is not limited except as by the appended claims.