[plt-scheme] Limiting Concurrent Connections to Web Server

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Mon Jan 12 11:57:50 EST 2009

Perhaps, I don't think I'm clever enough though.

Here's a hack that "works":

(define (make-limit-dispatcher num inner)
  (let ([sem (make-semaphore num)])
    (lambda (conn req)
      (parameterize ([current-custodian (current-server-custodian)])
        (thread
         (lambda ()
           (call-with-semaphore
            sem
            (lambda ()
              (inner conn req)))))))))

Basically before going inside the limit, it changes the resource
policy so that this connection's resources are charged to the whole
server, so when the connection goes down, the thread doesn't get
killed. If you do this, you won't get deadlocks, but you will get lots
of errors, because the connection's ports will die and the thread will
keep running.

The obvious kill-safe strategy[1] has the same problem.

1. Create a "limit manager" thread at the server level, it receives
requests from the dispatchers to do the work, but doesn't die. But if
the connection died, I don't know how to communicate that back to the
limit manager. This would serialize requests, so you'd need N of them,
where N is the limit. Mz threads are cheap, but not as cheap as Erlang
threads, so this might not be a great idea.

Jay

On Mon, Jan 12, 2009 at 9:52 AM, Robby Findler
<robby at eecs.northwestern.edu> wrote:
> Do you think it can be made kill-safe with the current mz?
>
> Robby
>
> On Mon, Jan 12, 2009 at 10:41 AM, Jay McCarthy <jay.mccarthy at gmail.com> wrote:
>> I can reproduce it. Essentially the problem is that when a connection
>> dies, the server kills the threads associated with it. In this case,
>> the killed threads were supposed to post to the semaphore when they
>> were done, but they never finished. Basically, the limiting is not
>> kill-safe [1].
>>
>> Jay
>>
>> 1. http://www.cs.utah.edu/plt/kill-safe/
>>
>> On Sat, Jan 10, 2009 at 2:15 PM, Henk Boom <lunarc.lists at gmail.com> wrote:
>>> Has anyone else had any luck duplicating this?
>>>
>>>    Henk
>>>
>>
>>
>>
>> --
>> Jay McCarthy <jay at cs.byu.edu>
>> Assistant Professor / Brigham Young University
>> http://teammccarthy.org/jay
>>
>> "The glory of God is Intelligence" - D&C 93
>> _________________________________________________
>>  For list-related administrative tasks:
>>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>
>>
>



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://teammccarthy.org/jay

"The glory of God is Intelligence" - D&C 93


Posted on the users mailing list.