You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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))
The text was updated successfully, but these errors were encountered:
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.
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.
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))
The text was updated successfully, but these errors were encountered: