Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

await-all doesn't await-all enough #9

Closed
kasterma opened this issue Aug 7, 2013 · 3 comments
Closed

await-all doesn't await-all enough #9

kasterma opened this issue Aug 7, 2013 · 3 comments

Comments

@kasterma
Copy link

kasterma commented Aug 7, 2013

The call to await-all at
https://github.com/Datomic/simulant/blob/master/src/simulant/sim.clj#L378
waits for all the actions dispatched at the time of calling to have occurred. In my simulation there is some nondeterministic behavior in the environment (in reaction to nondeterministic behavior of the software under test). This I have modeled by sending actions back and forth using a send-action service (see below). This means however that new actions will be dispatched by the current actions being performed. As a consequence the services are finalized too early (e.g. the action log temp file gets closed).

I don't know enough about java concurrency code yet to have a fix, but other than the obvious race condition something like:

(defn await-all
"Given a collection of objects, calls await on the agent for each one"
[coll](let [agents %28map via-agent-for coll%29]
%28apply await agents%29
%28when-not %28every? %28fn [^clojure.lang.Agent a] %28zero? %28.getQueueCount a%29%29%29 agents%29
%28recur coll%29%29))

could work. If I find a real solution (other than the (Thread/sleep 6000) that keeps things from crashing now) I'll submit it. Very curious about other solutions for this.

(defmethod sim/start-service :service.type/send-action
[conn process service](fn [action process]
;; test action has required keys
%28assert %28every? %28partial contains? action%29 [:action/type :agent/_actions]%29%29
;; send the action
%28sim/feed-action action process%29))

;; This service has nothing to finalize
(defmethod sim/finalize-service :service.type/send-action
[conn process service services-map]
true)

(defn create-send-action-service
"Create a send-action service for the sim."
[conn sim](let [id %28d/tempid :sim%29]
%28-> @%28d/transact conn [{:db/id id
:sim/_services %28e sim%29
:service/type :service.type/send-action
:service/key :simulant.sim/send-action}]%29
%28tx-ent id%29%29))

@mtnygard
Copy link
Contributor

mtnygard commented Aug 4, 2014

Picking this up after a long hiatus...

A question for you @kasterma, did the send-action service suffice? I'm thinking about a couple of ways to address this issue, and wondering if you found another approach later that you preferred.

@kasterma
Copy link
Author

kasterma commented Aug 4, 2014

For the immediate problem I was working on the whole simulation was later simplified so much that the problem went away. In running the simulation before simplification the problem was never resolved, but I recently found a paper which I think could be the basis for a real solution (Chandy and Lamport http://people.cs.umass.edu/~arun/cs677/reading/CL85.pdf). This is something I am looking in on the side, and not being very well versed in basic distributed algorithms getting to grips with it will probably take a little. If it leads to a general solution I'll make a pull request.

@mtnygard
Copy link
Contributor

mtnygard commented Aug 5, 2014

OK. I'm going to close this issue then.

@mtnygard mtnygard closed this as completed Aug 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants