合肥网站建设哪家好,wordpress 导入demo,wordpress微信缩图,深圳专业做网站排名哪家好akka 异常处理Akka演员承诺并发。 有什么更好的模拟方法#xff0c;看看使用商品硬件和软件处理1000万条消息需要花费多少时间#xff0c;而无需进行任何低级调整。我用Java编写了整个1000万条消息的处理过程#xff0c;整个结果令我惊讶。 当我在具有i5 – 4核心#xff0… akka 异常处理 Akka演员承诺并发。 有什么更好的模拟方法看看使用商品硬件和软件处理1000万条消息需要花费多少时间而无需进行任何低级调整。我用Java编写了整个1000万条消息的处理过程整个结果令我惊讶。 当我在具有i5 – 4核心4 Gb RAM计算机和JVM堆的Intel i5 – 4内核的iMac计算机上运行程序时该程序在23秒内处理了1000万台计算机。 我多次运行该程序平均时间为25秒。 因此我收到的吞吐量几乎在每秒40万条消息的范围内这是惊人的。 下图说明了用于模拟负载生成方案的流程。 警告每条消息在1秒钟后发送响应这对于实际情况而言并非正确的模拟。 在这种情况下消息处理将消耗堆和gc活动上一些未被考虑的资源。 该程序使用了Akka发布者的总体指导在75秒内处理了1000万条消息每条消息1秒 虽然没有任何限制。 该程序的代码库位于以下位置– https://github.com/write2munish/Akka-Essentials ApplicationManagerSystem创建actor并泵送至WorkerActor的流量 private ActorSystem system;private final ActorRef router;private final static int no_of_msgs 10 * 1000000;public ApplicationManagerSystem() {final int no_of_workers 10;system ActorSystem.create(LoadGeneratorApp);final ActorRef appManager system.actorOf(new Props(new UntypedActorFactory() {public UntypedActor create() {return new JobControllerActor(no_of_msgs);}}), jobController);router system.actorOf(new Props(new UntypedActorFactory() {public UntypedActor create() {return new WorkerActor(appManager);}}).withRouter(new RoundRobinRouter(no_of_workers)));}private void generateLoad() {for (int i no_of_msgs; i 0; i--) {router.tell(Job Id i # send);}System.out.println(All jobs sent successfully);} 一旦WorkerActor收到了消息则计划将响应在1000毫秒后发送 public class WorkerActor extends UntypedActor {private ActorRef jobController;Overridepublic void onReceive(Object message) throws Exception {using scheduler to send the reply after 1000 millisecondsgetContext().system().scheduler().scheduleOnce(Duration.create(1000, TimeUnit.MILLISECONDS),jobController, Done);}public WorkerActor(ActorRef inJobController) {jobController inJobController;}} 来自WorkerActor的响应消息被发送到JobControllerActor后者收集所有响应。 public class JobControllerActor extends UntypedActor {int count 0;long startedTime System.currentTimeMillis();int no_of_msgs 0;Overridepublic void onReceive(Object message) throws Exception {if (message instanceof String) {if (((String) message).compareTo(Done) 0) {count;if (count no_of_msgs) {long now System.currentTimeMillis();System.out.println(All messages processed in (now - startedTime) 1000 seconds);System.out.println(Total Number of messages processed count);getContext().system().shutdown();}}}}} 参考 教程HibernateJPA和Spring MVC –来自Akka Essentials博客的JCG合作伙伴 Munish K Gupta的第2部分 。 翻译自: https://www.javacodegeeks.com/2012/05/processing-10-million-messages-with.htmlakka 异常处理