Thank you for working on this Danyil. I think it is fair to test what
the defaults give you.

Would you please add this file to your tests (and each of its three
ways of running?) It would be interesting to compare the performance
of Racket versus the particular Web server library. (The Web server
sets up a lot of safety state per connection to ensure that each
individual connection doesn't run out of memory or crash anything. I
am curious what the cumulative effect of all those features and
protections are.)


#lang racket/base
(require racket/tcp

(define message #"Lorem ipsum...") ;; XXX fill this in
(define len (bytes-length message))

(define (serve! r w)
  (let read-loop ()
    (define b (read-bytes-line r 'any))
    (unless (or (eof-object? b) (bytes=? b #""))
  (close-input-port r)
  (write-bytes #"HTTP/1.1 200 OK\r\n" w)
  (write-bytes #"Connection: close\r\n" w)
  (write-string (format "Content-Length: ~a\r\n" len) w)
  (write-bytes #"\r\n" w)
  (write-bytes message w)
  (close-output-port w))

(define port-no 5000)
(define (setup! k)
  (define l (tcp-listen port-no 500 #t ""))
  (k l)
  (tcp-close l))

(define (single-at-a-time l)
  (let loop ()
    (define-values (r w) (tcp-accept l))
    (serve! r w)

(define (many-at-a-time l)
  (let loop ()
    (define-values (r w) (tcp-accept l))
    (thread (λ () (serve! r w)))

(define (k-places l)
  (local-require racket/place)

  (define-values (jobs-ch-to jobs-ch-from) (place-channel))
  (define ps
    (for/list ([i (in-range (processor-count))])
       (let loop ()
         (define r*w (place-channel-get jobs-ch-from))
         (serve! (car r*w) (cdr r*w))

  (let loop ()
    (define-values (r w) (tcp-accept l))
    (place-channel-put jobs-ch-to (cons r w))

(module+ main
   (match (current-command-line-arguments)
     [(vector "single")
     [(vector "many")
     [(vector "places")

-=[     Jay McCarthy         ]=-
-=[ Associate Professor        PLT @ CS @ UMass Lowell     ]=-
-=[ Moses 1:33: And worlds without number have I created; ]=-

You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
For more options, visit

Reply via email to