Created
August 27, 2009 21:54
-
-
Save GeorgeJahad/176595 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
First create a server with a socket repl using | |
clojure.contrib.server-socket: | |
(defn start-server[host port] | |
(create-repl-server port) | |
(repl)) | |
Then create a bunch of netbots and have each use a repl to communicate | |
with the server repl. Have that repl request a new job from | |
the server each time it finishes a job: | |
(defn start-client[host port] | |
(let [s (Socket. host port) | |
in (.getInputStream s) | |
rdr (LineNumberingPushbackReader. (InputStreamReader. in)) | |
wrtr (OutputStreamWriter. (.getOutputStream s))] | |
(loop [] | |
;; skip repl prompt | |
(read rdr) | |
(println "time is " (.getTime (Calendar/getInstance))) | |
(binding [*out* wrtr] | |
(println "(packer/get-next-job)")) | |
(if-let [job (read rdr)] | |
(do | |
(eval job) | |
(recur)) | |
(println "end time is " (.getTime (Calendar/getInstance))))))) | |
Then define packer/get-next-job to return what ever | |
jobs you want to the netbots. For example, I'm running the following | |
right now on 17netbots on the cluster, to feed them packing jobs from | |
a list of remaining collections: | |
(defn get-next-job [] | |
(if-let [next-job (first @remaining-jobs)] | |
(do | |
(swap! remaining-jobs #(next %)) | |
`(packer-run nil | |
[:start-mapper | |
~next-job ~(.substring next-job (.length "/mnt/data/"))])) | |
'nil)) | |
If I want to change up the jobs I'm serving, I just go to the server | |
repl and redefine get-next-job, e.g to put the netbots to sleep: | |
(defn get-next-job [] | |
'(Thread/sleep 60000)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment