开发者

Model for a Scheduling System

We have built a scheduling system to control our client's appointments. This system is similar to the one used by Prometric to schedule an exam. The main concerns are: guarantee that there is no overscheduling, support at least one hundred thousand appointments per month and allow to increase/decrease the testing center capacity easily.

We devised the following design based on Capacity Vectors. We assumed that each appointment requires at least five minutes. A vector is composed by 288 slots (24 hours * 12 slots per hour), each one represented by one byte. The vector allows the system to represent up to 255 appointments every five minutes. The information used is composed by two vectors: one to store the testing center capacity (NOMINAL CAPACITY) and another to store the used capacity (USED CAPACITY). To recover the current capacity (CURRENT CAPACITY), the system takes the testing NOMINAL CAPACITY and subtracts the USED CAPACITY.

The database has the following structure:

NOMINAL CAPACITY

The nominal capacity represents the capacity for work days (Mon-Fri).

| TEST_CENTER_ID | NOMINAL_CAPACITY
| 1          | 0000001212121212....0000
| 2          | 0000005555555555....0000
...
| N          | 0000000000010101....0000

USED CAPACITY

This table stores the used capacity for each day / testing center.

| TEST_CENTER_ID | DATE       | USED_CAPACITY
| 1          | 01/01/2010 | 0000001010101010...0000
| 1          | 01/02/2010 | 0000000202020202...0000
| 1          | 01/03/2010 | 0000001010101010...0000
...
| 2          | 01/01/2010 | 0000001010101010...0000
...
| N          | 01/01/2010 | 0000000000000000...0000

After the client chose the testing center and a date, the system presents the available slots doing the following calculation. For example:

TEST_CENTER_ID   1
DATE             01/01/2010
NOMINAL_CAPACITY 0000001212121212...0000
USED_CAPACITY   开发者_开发问答 0000001010101010...0000
AVAILABLE_CAPAC  0000000202020202...0000

If the client decides to schedule an appointment, the system locks the chosen day (a row in # USED CAPACITY table) and increases the corresponding byte.

The system is working well now, but we foresee contention problems if the number of appointments increases too much.

Does anyone has a better/another model for this problem or suggestions to improve it?

We have thought in avoiding the contention by sub-diving the representation of a vector in hour and changing to an optimistic lock strategy. For example:

| TEST_CENTER_ID | DATE       | USED_CAPACITY_0 | USED_CAPACITY_1 | ... | USED_CAPACITY_23
| 1             | 01/01/2010 | 000000101010    | 1010...         | ... | ...0000

This way will don't need to lock a row and reduce collision events.


Here's one idea:

You can use optimistic locking with your current design. Instead of using a separate version number or timestamp to check whether the entire row has been modified, save a memento of the used_capacity array when the row is read. You only lock on update, at which time you compare just the modified slot byte to see if it's been updated. If not, you can embed the new value into that one element without modifying the others, thus retaining modifications to other slots performed by other processes since your initial read.

This should work as well on an set of adjacent bytes for appointments that are longer than 5 minutes.

If you know the slot(s) in question when you initially read, then you can just save the beginning array index and salient values instead of the entire array.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜