我正在分析(visualvm)来自 AKKA 文档的示例集群应用程序之一,我看到垃圾收集在每次 GC 期间清理了每个请求参与者。无法完全理解使用后明确杀死actor的建议。我的actorsystem 和actors 由SPRING IOC 容器管理,我使用spring 扩展间接actor-producer 来创建actors。“聚合器”参与者正在每次 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();
}
}