4

some-operation私は(例のように)一連の機能を持っていsendますsend-off

(defn some-operation [agent-state]
  (dosync
   (let [updated (foo agent-state)] ;; derive new state from old one
     (alter bar whatev updated) ;; reflect the new state in the world
     (send *agent* some-operation) ;; "recur"
     updated) ;; value for recur
   ))

(send (agent {}) some-operation)

このアプローチは、アプリを開発しているときにうまくいきました。しかし、コードベースにいくつかの変更を加えた後、エージェントはしばらくすると実行を停止します (「しばらく」は数秒で、数千の「再帰的」呼び出しです)。

それらの状態はドメイン内で有効であり、エージェント自体は有効ではなく、ブロックFAILEDでライブロックしていないことは確かです(競合を測定できます)。dosync

私の疑いは、何らかの理由で、JVM/OS が基になるエグゼキューター スレッドの実行を妨げていることです。しかし、この仮定が正しいかどうかを確認する方法がわかりません。

一般的に、送信エージェントが保留中の「送信」を実行できない理由として考えられるものは何ですか? 何を検査/測定できますか?

更新- デバッグ用に次の変更を行うと...

(defn some-operation [agent-state]
  (let [f (future
            (dosync
             ...) ;; the whole operation, as per the previous example
            )]
    (Thread/sleep 1000) ;; give the operation some time
    (if (realized? f)
      @f

      ;; not realized: we deem the operation as blocking indefinetely
      (do
        (println :failed)
        (send *agent* some-operation)
        agent-state))))

...エージェントはまだスタックしており、印刷さえしません:failed

4

2 に答える 2

0

送信プールは制限されているため、同時に実行できるエージェントの数は限られています (この回答を参照してください)。これは事実でしょうか?

于 2013-07-23T10:42:26.237 に答える