Changeset 3447

Show
Ignore:
Timestamp:
07/15/08 14:16:38 (6 months ago)
Author:
hans
Message:

Add statistics handler to measure handler execution speed.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/bknr/web/src/bknr.web.asd

    r3344 r3447  
    8080                                                                 "site")) 
    8181 
     82                                             (:file "handler-statistics-handler" 
     83                                                    :depends-on ("handlers")) 
     84 
    8285                                             (:file "template-handler" 
    8386                                                    :depends-on ("handlers")) 
  • trunk/bknr/web/src/web/handlers.lisp

    r3398 r3447  
    211211                 :initform "text/html") 
    212212   (site :initarg :site 
    213          :reader page-handler-site)) 
     213         :reader page-handler-site) 
     214   (statistics :initform (make-handler-statistics) 
     215               :accessor page-handler-statistics)) 
    214216  (:documentation "Simple page handler publishing a serve request under a simple URL")) 
    215217 
     
    224226  (print-unreadable-object (handler stream :type t) 
    225227    (format stream "~A" (page-handler-prefix handler)))) 
     228 
     229;; Each handler has a statistics record that keeps track of the 
     230;; slowest and fastest URLs on this handler and the average time that 
     231;; processing on this handler takes. 
     232 
     233(defconstant +statistics-keep-atypical-count+ 10) 
     234 
     235(defstruct (handler-statistics (:conc-name hs-)) 
     236  (slowest (make-array +statistics-keep-atypical-count+ :initial-element nil)) 
     237  (fastest (make-array +statistics-keep-atypical-count+ :initial-element nil)) 
     238  (count 0) 
     239  average) 
     240 
     241(defun slowest-time (statistics) 
     242  (or (car (aref (hs-slowest statistics) 0)) 
     243      0)) 
     244 
     245(defun fastest-time (statistics) 
     246  (or (car (aref (hs-fastest statistics) 0)) 
     247      most-positive-fixnum)) 
     248 
     249(defun note-run-time-for-statistics (handler run-time) 
     250  (let ((statistics (page-handler-statistics handler))) 
     251    (when (< run-time (fastest-time statistics)) 
     252      (setf (aref (hs-fastest statistics) 0) (cons run-time (tbnl:script-name*)) 
     253            (hs-fastest statistics) (sort (hs-fastest statistics) #'> 
     254                                          :key (lambda (entry) 
     255                                                 (or (car entry) 
     256                                                     most-positive-fixnum))))) 
     257    (when (> run-time (slowest-time statistics)) 
     258      (setf (aref (hs-slowest statistics) 0) (cons run-time (tbnl:script-name*)) 
     259            (hs-slowest statistics) (sort (hs-slowest statistics) #'< 
     260                                          :key (lambda (entry) 
     261                                                 (or (car entry) 
     262                                                     0))))) 
     263    (cond 
     264      ((plusp (hs-count statistics)) 
     265       (setf (hs-average statistics) (/ (+ (* (hs-count statistics) (hs-average statistics)) 
     266                                           run-time) 
     267                                        (1+ (hs-count statistics)))) 
     268       (incf (hs-count statistics))) 
     269      (t 
     270       (setf (hs-average statistics) run-time 
     271             (hs-count statistics) 1))))) 
    226272 
    227273(defgeneric handle (page-handler) 
     
    280326                                                        (website-show-error-page *website* e)) 
    281327                                                    (do-error-log-request e))))))) 
    282       (handle handler)))) 
     328      (let ((start (get-internal-real-time))) 
     329        (prog1 
     330            (handle handler) 
     331          (let ((duration (- (get-internal-real-time) start))) 
     332            (note-run-time-for-statistics handler duration))))))) 
     333 
    283334 
    284335(defmethod handle ((page-handler page-handler)) 
  • trunk/projects/bos/web/webserver.lisp

    r3398 r3447  
    239239                                        ("/statistics" statistics-handler) 
    240240                                        ("/rss" rss-handler) 
     241                                        ("/handler-statistics" bknr.web::handler-statistics-handler) 
    241242                                        ("/favicon.ico" 
    242243                                         file-handler 
  • trunk/projects/lisp-ecoop/src/webserver.lisp

    r3359 r3447  
    2626                                        images 
    2727                                        stats 
     28                                        ("/handler-statistics" bknr.web::handler-statistics-handler) 
    2829                                        mailinglist 
    2930                                        mailinglist-registration 
  • trunk/thirdparty/closure-common/closure-common.asd

    r3436 r3447  
    2727       (error "conflicting unicode configuration.  Please recompile.") 
    2828       (pushnew :rune-is-integer *features*)) 
    29       ((ignore-errors (code-char 70000)) 
     29      (#+cmu (ignore-errors (code-char 70000)) 
     30       #-cmu (code-char 70000) 
    3031       (when (test #xD800) 
    3132         (format t " WARNING: Lisp implementation doesn't use UTF-16, ~