我正在剖析(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