cpp: TNonblockingServer: Allow unrun tasks to expire after a time limit
authorDavid Reiss <dreiss@apache.org>
Tue, 9 Mar 2010 05:19:45 +0000 (05:19 +0000)
committerDavid Reiss <dreiss@apache.org>
Tue, 9 Mar 2010 05:19:45 +0000 (05:19 +0000)
commit068f4169b9c2cd9f93ad32e99c5b0d5b786e0bc1
treeda5926056c211612a1c1856e83fc7493f2af5f12
parent58e4d2c6e3b237825b573116d4e06781733ab5f5
cpp: TNonblockingServer: Allow unrun tasks to expire after a time limit

Enhance ThreadManager to allow a expiration time interval to be assigned
to tasks, and expire those tasks after that time limit has passed.
Enhance TNonblockingServer to utilize this capability so it can be used
for overload resilience.

Note: expired entries are only removed from the queue head, so the
mechanism in ThreadManager may not do what you expect if you have
heterogeneous expiration times. That's not an issue with
TNonblockingServer (which will give all tasks the same limit) and might
not be in other cases where most tasks have the same limit and the rest
execute quickly. A full-up timeout queue would be more complex and have
greater overhead than that used here. It's unnecessary for the task at
hand so I didn't go that route...

The TNonblocking interface is simple: a setTaskExpireTime() accepts a
64-bit millisecond argument. 0 means infinite. A getTaskExpireTime()
accessor completes the interface.

The ThreadManager interface involves an added argument to add() for the
expiration interval and a setExpireCallback() function for setting a
callback that is called for expired tasks (for this project this is
necessary to shut down the associated connection).

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@920673 13f79535-47bb-0310-9956-ffa450edef68
lib/cpp/src/concurrency/ThreadManager.cpp
lib/cpp/src/concurrency/ThreadManager.h
lib/cpp/src/server/TNonblockingServer.cpp
lib/cpp/src/server/TNonblockingServer.h