我正在剖析(visualvm)來自AKKA文檔的示例集羣應用程序之一,並且我在每個GC期間看到清理每個請求演員的垃圾收集。無法完全理解使用後顯式殺死actor的建議。我的演員系統和演員由SPRING IOC容器管理,我使用spring extension直接演員製作人來創建演員。 「聚合器」actor正在每個GC上收集垃圾,我確實監視了可視VM中的實例數量。
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class StatsService extends AbstractActor {
private final LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
@Autowired
private ActorSystem actorSystem;
private ActorRef workerRouter;
@Override
public void preStart() throws Exception {
System.out.println("Creating Router" + this.getClass().getCanonicalName());
workerRouter = getContext().actorOf(SPRING_PRO.get(actorSystem)
.props("statsWorker").withRouter(new FromConfig()), "workerRouter");
super.preStart();
}
@Override
public Receive createReceive() {
return receiveBuilder()
.match(StatsJob.class, job -> !job.getText().isEmpty(), job -> {
final String[] words = job.getText().split(" ");
final ActorRef replyTo = sender();
final ActorRef aggregator = getContext().actorOf(SPRING_PRO.get(actorSystem)
.props("statsAggregator", words.length, replyTo));
for (final String word : words) {
workerRouter.tell(new ConsistentHashableEnvelope(word, word),
aggregator);
}
})
.build();
}
}
http:// stackoverflow。com/questions/23066264/can-wrapping-akka-actors-in-class-actors-caused-memory-leaks < - 相關問題 – 2014-04-14 17:33:55