 (defn- send-response-log
   "Function that will 'send-off' for asynchronously logging response metrics.
    This function itself should not nothing blocking."
-  [time-in-millis log-writer num-threads]
-  (send-off response-log (fn [count]
+  [time-in-millis response-log-agent log-writer num-threads]
+  (send-off response-log-agent (fn [count]
               (.write log-writer (str "timestamp:" (System/currentTimeMillis) " threads: " num-threads " duration: " time-in-millis "\n"))
               (if (= 10 count) 
                 (do 

  ([url] (run-load-test url (-> (Runtime/getRuntime) .availableProcessors)))
  ([url num-threads]
    (println "Starting load test")
    (with-open [log-writer (writer "/tmp/test2.txt")]
      (println "Log file opened")
      (http/with-connection-pool {:timeout 500 :threads 20 :insecure? false :default-per-route 20}
        (let [futures (doall (for [i (range num-threads)]
                             (future
                               (println "send-requests starting in thread: " (Thread/currentThread))
                               (send-requests url 10 log-writer num-threads))))]
          (println "starting")
          (doseq [f futures]
            ; wait for each future to complete
            (deref f))
          ; (println (deref f 900 #(future-cancel f))) ; this isn't working (returns function but doesn't execute it)
          (println "Done load test."))))))
  

; used for sending response logs to and serializing them to output
(def response-log (agent 0))

(defmacro duration-in-millis
  "Evaluates expr and records the time it took in millis.

  (:require [clj-http.client :as http]
            [clojure.java.io :as io]))

(declare send-requests)

(defn run-load-test
  "Execute load test against given URL
