Browse Source

Improve rescue behaviour (see comment)

master
eta 2 months ago
parent
commit
b030a20008
  1. 27
      trackernet.lisp

27
trackernet.lisp

@ -14,6 +14,7 @@
(defparameter *trackernet-scrape-interval* 4)
(defparameter *prediction-expiry-secs* 60)
(defparameter *train-active-expiry-secs* 30)
(defparameter *rescue-grace-period-secs* 15)
(defparameter *train-active-expiry-secs-real* 360)
(defparameter *train-set-code-expiry-secs* 360)
(defparameter *track-code-expiry-secs* 10)
@ -571,9 +572,12 @@
(bgcol :green) key (colreset) code-station train)
(statsd-inc "intertube.new")
;; make a rescuable thingy
;; (see the note inside GET-RESCUABLE-TRAINS for more)
(red:setex (format nil "~A-rescue-~A"
line-code tid)
*train-active-expiry-secs-real*
(+ *train-active-expiry-secs*
*rescue-grace-period-secs*
*train-active-expiry-secs-real*)
track-code))
;; mark this train as active
(red:setex (format nil "~A-active-~A"
@ -682,12 +686,24 @@
do (red:zadd new-train ts (cpk-base64 data))))
(defun get-rescuable-trains (line-code)
"Gets rescuable trains for the given LINE-CODE, i.e. trains that were created recently that could be joined onto the end of stale trains."
(mapcar
(lambda (x)
(cons
(format nil "~A-train-~A" line-code (subseq x #.(length "D-rescue-")))
(red:get x)))
(get-all (format nil "~A-rescue-*" line-code))))
(delete-if
(lambda (x)
;; This is kind of subtle: to prevent old trains screwing up
;; the rescue of new trains, we add a grace period to the TTL
;; of the rescue key that's the length of time it takes for
;; an active train to become inactive (plus a few seconds).
;;
;; This means that an old train can't snatch new trains until
;; trains that could conceivably have just expired and be
;; the most likely candidate have had their go.
(> (red:ttl x) *train-active-expiry-secs-real*))
(get-all (format nil "~A-rescue-*" line-code)))))
(defun get-dijkstra-path (previous-table goal)
(nreverse
@ -815,6 +831,7 @@
(red:incr (format nil "~A-code-archives-~A"
line-code (track-code last-data)))
(statsd-inc "intertube.archived")
(statsd-counter "intertube.archived-records" records-archived)
(conspack-encode-to-archive tar-out filename archive-data)
(red:del key)
(values records-archived last-data unique-track-code-count)))
@ -958,9 +975,9 @@ Stop if *TRACKERNET-KILL-SWITCH* is set to T."
"Archive all trains that have expired."
(let ((trains (get-archivable-trains)))
(unless (null trains)
;; sort the trains earliest-to-latest,
;; so rescue chaining has a chance of working
(sort trains #'<
;; sort the trains latest-to-earliest,
;; so trains that just dropped out can be quickly rescued
(sort trains #'>
:key #'redis-last-score)
(statsd-gauge "intertube.maybe-archivable" (length trains))
(handler-case

Loading…
Cancel
Save