   ;; TODO: log
   (println response)
 
-  (http/post (:winnotice dsp)
+  (http/post  (:winnotice dsp)
+             ;; FIXME: options
              {:id (:advertiserId response)
               :price (+ 1 second-price)
               :isClick (click? result response)}))
 
 (defn gen-request [n]
   (let [c (chan)]
-    (go-loop [i n]
-      (>! c request)
-      (if (< 0 i)
-        (recur (- i 1))
-        (close! c)))
+    (thread
+      (loop [i n]
+        (>!! c request)
+        (if (< 0 i)
+          (recur (- i 1))
+          (close! c))))
     c))
 
 (defn process [c]
-  (let [sig (chan)]
-   (go-loop []
-     (if-let [{:keys [req result]} (<! c)]
-       (let [xf (comp
-                 (map (fn [dsp] [dsp (http/post (:url dsp) (assoc options :body (json/write-str req)))]))
-                 (map validate)
-                 ;; TODO: log validated responses
-                 (filter succeed?)
-                 (map (fn [[_ res]] (:valid res))))]
-         (some->> (sequence xf @dsps)
-                  (pick-winner-and-second-price (:floorPrice req))
-                  (winnotice req result))
-         (recur))
-       (close! sig)))
-   sig))
+  (thread
+    (loop []
+      (when-let [{:keys [req result]} (<!! c)]
+        (let [xf (comp
+                  (map (fn [dsp] [dsp (http/post (:url dsp) (assoc options :body (json/write-str req)))]))
+                  (map validate)
+                  ;; TODO: log validated responses
+                  (filter succeed?)
+                  (map (fn [[_ res]] (:valid res))))]
+          (some->> (sequence xf @dsps)
+                   (pick-winner-and-second-price (:floorPrice req))
+                   (winnotice req result)
+                   )
+          (recur))))))
 
 
-(defn -main []
-  (time (let [c (gen-request 100)
-         sig (process c)]
-     (<!! sig))))
+(defn -main [& args]
+  (time (let [c (gen-request 1000)]
+          (doseq [sig (vec (map (fn [_] (process c)) (range 64)))]
+            (<!! sig)))))

   :result [true]})

(defn validate [[dsp res]]
  (let [{:keys [status body error]} @res
        body (and body (json/read-str body :key-fn keyword))
        {:keys [id bidPrice advertiserId]} body
        ret (cond
              (= status 204) {:nobid "no bid"}

(ns s7p.core
  (:require [clojure.data.json :as json]
            [org.httpkit.client :as http]
            [clojure.core.async :refer [thread chan close!  <!! >!!]])
  (:gen-class)
  )

(def options {:timeout 100
              :keepalive 3000})

(def someurl "")

(def dsps (atom
           [{:id "1"
             :url someurl
             :winnotice someurl}
            {:id "2"
             :url someurl
             :winnotice someurl}
            {:id "3"
             :url someurl
             :winnotice someurl}
            {:id "4"
             :url someurl
             :winnotice someurl}
            {:id "5"
             :url someurl
             :winnotice someurl}
            {:id "6"
             :url someurl
             :winnotice someurl}
            {:id "7"
             :url someurl
             :winnotice someurl}
            ]))

(def advertisers [{:id "1"} {:id "2"} {:id "3"} {:id "4"}])

