在 docker 个实例上使用带有动脉的 akka 远程处理时出错
Error using akka remoting with artery over docker instances
首先,对不起我的英语。 Google翻译对我帮助很大,哈哈。
我的问题是:
我有两个使用 akka
和 java
开发的示例项目:example-remote-client.jar 和 example-remote-server.jar
我正在使用动脉序列化,并且正在尝试通过 akka-remoting 从客户端向服务器发送消息。
执行此操作的客户演员是:
public class ClientActor extends AbstractActor {
public static Props props() {
return Props.create(ClientActor.class);
}
public ClientActor() {
ActorSelection selection = getContext().system().actorSelection("akka://server@localhost:5001/user/server-process");
selection.tell(new MessageRequest(), getSelf());
}
public Receive createReceive() {
return receiveBuilder().match(MessageResponse.class, msg -> {
System.out.println(msg.getMessage());
}).build();
}
}
我的客户端配置:
akka {
loglevel = "DEBUG"
actor {
provider = remote
allow-java-serialization = off
serializers {
java = "akka.serialization.JavaSerializer"
myown = "serializers.ExampleByteBufSerializer"
}
serialization-bindings {
"java.lang.String" = myown
"protocol.MessageRequest" = myown
"protocol.MessageResponse" = myown
"java.lang.Boolean" = myown
}
}
remote {
artery {
enabled = on
canonical.hostname = "192.168.0.250" # external (logical) hostname
canonical.port = 5000 # external (logical) port
bind.hostname = "localhost" # internal (bind) hostname
bind.port = 10000 # internal (bind) port
}
}
}
服务器actor很虚,我觉得没必要贴在这里。但是它的配置是:
akka {
loglevel = "DEBUG"
actor {
provider = remote
allow-java-serialization = off
serializers {
java = "akka.serialization.JavaSerializer"
myown = "serializers.ExampleByteBufSerializer"
}
serialization-bindings {
"java.lang.String" = myown
"protocol.MessageRequest" = myown
"protocol.MessageResponse" = myown
"java.lang.Boolean" = myown
}
}
remote {
artery {
enabled = on
canonical.hostname = "192.168.0.250" # external (logical) hostname
canonical.port = 5001 # external (logical) port
bind.hostname = "localhost" # internal (bind) hostname
bind.port = 10001 # internal (bind) port
}
}
}
两个 jar 都部署在同一“192.168.0.250 机器”上的 docker 个实例 运行 上,如下所示:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d2970bd20371 openjdk:alpine "sh" 34 minutes ago Up 34 minutes 0.0.0.0:5001->10001/tcp ex-remoting-server
36a67fea8590 openjdk:alpine "sh" 34 minutes ago Up 34 minutes 0.0.0.0:5000->10000/tcp ex-remoting-client
服务器启动正常,日志如下:
[DEBUG] [07/04/2017 13:46:18.473] [main] [EventStream(akka://server)] logger log1-Logging$DefaultLogger started
[DEBUG] [07/04/2017 13:46:18.473] [main] [EventStream(akka://server)] Default Loggers started
[DEBUG] [07/04/2017 13:46:18.495] [main] [akka.serialization.Serialization(akka://server)] Replacing JavaSerializer with DisabledJavaSerializer, due to `akka.actor.allow-java-serialization = off`.
[INFO] [07/04/2017 13:46:18.628] [main] [akka.remote.artery.ArteryTransport(akka://server)] Started embedded media driver in directory [/dev/shm/aeron-root-server-efd42dec-452d-406c-8d1d-807e0d8ff7fc]
[INFO] [07/04/2017 13:46:18.693] [main] [akka.remote.artery.ArteryTransport(akka://server)] Remoting started; listening on address: [akka://server@192.168.0.250:5001] with UID [-2663186266051514585]
但是当我尝试启动客户端时,出现以下错误:
[ERROR] [07/04/2017 14:09:05.250] [client-akka.actor.default-dispatcher-10] [akka://server@192.168.0.250:5001/] swallowing exception during message send
io.aeron.exceptions.RegistrationException: Insufficient usable storage for new log of length=50332096 in /dev/shm (shm)
at io.aeron.ClientConductor.onError(ClientConductor.java:285)
at io.aeron.DriverListenerAdapter.onMessage(DriverListenerAdapter.java:79)
at org.agrona.concurrent.broadcast.CopyBroadcastReceiver.receive(CopyBroadcastReceiver.java:100)
at io.aeron.DriverListenerAdapter.pollMessage(DriverListenerAdapter.java:59)
at io.aeron.ClientConductor.doWork(ClientConductor.java:422)
at io.aeron.ClientConductor.awaitResponse(ClientConductor.java:447)
at io.aeron.ClientConductor.addPublication(ClientConductor.java:177)
at io.aeron.Aeron.addPublication(Aeron.java:165)
at akka.remote.artery.AeronSink$$anon.<init>(AeronSink.scala:103)
at akka.remote.artery.AeronSink.createLogicAndMaterializedValue(AeronSink.scala:100)
at akka.stream.impl.GraphStageIsland.materializeAtomic(PhasedFusingActorMaterializer.scala:627)
at akka.stream.impl.PhasedFusingActorMaterializer.materialize(PhasedFusingActorMaterializer.scala:458)
at akka.stream.impl.PhasedFusingActorMaterializer.materialize(PhasedFusingActorMaterializer.scala:420)
at akka.stream.impl.PhasedFusingActorMaterializer.materialize(PhasedFusingActorMaterializer.scala:415)
at akka.stream.scaladsl.RunnableGraph.run(Flow.scala:439)
at akka.remote.artery.Association.akka$remote$artery$Association$$runOutboundOrdinaryMessagesStream(Association.scala:570)
at akka.remote.artery.Association.runOutboundStreams(Association.scala:510)
at akka.remote.artery.Association.associate(Association.scala:502)
at akka.remote.artery.AssociationRegistry.association(Association.scala:763)
at akka.remote.artery.ArteryTransport.association(ArteryTransport.scala:932)
at akka.remote.artery.ArteryTransport.send(ArteryTransport.scala:918)
at akka.remote.RemoteActorRef.$bang(RemoteActorRefProvider.scala:563)
at akka.actor.ActorRef.tell(ActorRef.scala:124)
at akka.actor.ActorSelection$.rec(ActorSelection.scala:250)
at akka.actor.ActorSelection$.deliverSelection(ActorSelection.scala:254)
at akka.actor.ActorSelection.tell(ActorSelection.scala:45)
at actors.ClientActor.<init>(ClientActor.java:21)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at akka.util.Reflect$.instantiate(Reflect.scala:44)
at akka.actor.NoArgsReflectConstructor.produce(IndirectActorProducer.scala:105)
at akka.actor.Props.newActor(Props.scala:213)
at akka.actor.ActorCell.newActor(ActorCell.scala:563)
at akka.actor.ActorCell.create(ActorCell.scala:589)
at akka.actor.ActorCell.invokeAll(ActorCell.scala:462)
at akka.actor.ActorCell.systemInvoke(ActorCell.scala:484)
at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:282)
at akka.dispatch.Mailbox.run(Mailbox.scala:223)
at akka.dispatch.Mailbox.exec(Mailbox.scala:234)
at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
我也尝试用这些发送消息 "ActorSelection paths":
"akka://server@192.168.0.250:5001/user/server-process"
"akka://server@localhost:5001/user/server-process"
"akka://server@192.168.0.250:10001/user/server-process"
"akka://server@localhost:10001/user/server-process"
但错误仍然出现。
同样重要的是要澄清,服务器演员的演员路径是:
akka://server/user/server-process
少了什么?我正在使用 akka 2.5.3 版本...
谢谢。
我不太确定 Akka 规范与绑定寻址的工作原理。但我的猜测是 bind.hostname
是实际 IP 或由它将侦听的主机名解析的 IP。在这种情况下,localhost
转换为 127.0.0.1
,这意味着容器将只接受 127.0.0.1
上的连接。
尝试将 bind.hostname
设置为 0.0.0.0
。这将允许来自容器外部 IP 地址的连接(从主机通过端口 5001)。
尝试将 /dev/shm
卷的大小设置得更大。在 docker-compose 文件中,您可以简单地添加此选项:shm_size: 500M
。此卷是 aeron 用来缓冲消息的共享内存 space。
首先,对不起我的英语。 Google翻译对我帮助很大,哈哈。
我的问题是:
我有两个使用 akka
和 java
开发的示例项目:example-remote-client.jar 和 example-remote-server.jar
我正在使用动脉序列化,并且正在尝试通过 akka-remoting 从客户端向服务器发送消息。
执行此操作的客户演员是:
public class ClientActor extends AbstractActor {
public static Props props() {
return Props.create(ClientActor.class);
}
public ClientActor() {
ActorSelection selection = getContext().system().actorSelection("akka://server@localhost:5001/user/server-process");
selection.tell(new MessageRequest(), getSelf());
}
public Receive createReceive() {
return receiveBuilder().match(MessageResponse.class, msg -> {
System.out.println(msg.getMessage());
}).build();
}
}
我的客户端配置:
akka {
loglevel = "DEBUG"
actor {
provider = remote
allow-java-serialization = off
serializers {
java = "akka.serialization.JavaSerializer"
myown = "serializers.ExampleByteBufSerializer"
}
serialization-bindings {
"java.lang.String" = myown
"protocol.MessageRequest" = myown
"protocol.MessageResponse" = myown
"java.lang.Boolean" = myown
}
}
remote {
artery {
enabled = on
canonical.hostname = "192.168.0.250" # external (logical) hostname
canonical.port = 5000 # external (logical) port
bind.hostname = "localhost" # internal (bind) hostname
bind.port = 10000 # internal (bind) port
}
}
}
服务器actor很虚,我觉得没必要贴在这里。但是它的配置是:
akka {
loglevel = "DEBUG"
actor {
provider = remote
allow-java-serialization = off
serializers {
java = "akka.serialization.JavaSerializer"
myown = "serializers.ExampleByteBufSerializer"
}
serialization-bindings {
"java.lang.String" = myown
"protocol.MessageRequest" = myown
"protocol.MessageResponse" = myown
"java.lang.Boolean" = myown
}
}
remote {
artery {
enabled = on
canonical.hostname = "192.168.0.250" # external (logical) hostname
canonical.port = 5001 # external (logical) port
bind.hostname = "localhost" # internal (bind) hostname
bind.port = 10001 # internal (bind) port
}
}
}
两个 jar 都部署在同一“192.168.0.250 机器”上的 docker 个实例 运行 上,如下所示:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d2970bd20371 openjdk:alpine "sh" 34 minutes ago Up 34 minutes 0.0.0.0:5001->10001/tcp ex-remoting-server
36a67fea8590 openjdk:alpine "sh" 34 minutes ago Up 34 minutes 0.0.0.0:5000->10000/tcp ex-remoting-client
服务器启动正常,日志如下:
[DEBUG] [07/04/2017 13:46:18.473] [main] [EventStream(akka://server)] logger log1-Logging$DefaultLogger started
[DEBUG] [07/04/2017 13:46:18.473] [main] [EventStream(akka://server)] Default Loggers started
[DEBUG] [07/04/2017 13:46:18.495] [main] [akka.serialization.Serialization(akka://server)] Replacing JavaSerializer with DisabledJavaSerializer, due to `akka.actor.allow-java-serialization = off`.
[INFO] [07/04/2017 13:46:18.628] [main] [akka.remote.artery.ArteryTransport(akka://server)] Started embedded media driver in directory [/dev/shm/aeron-root-server-efd42dec-452d-406c-8d1d-807e0d8ff7fc]
[INFO] [07/04/2017 13:46:18.693] [main] [akka.remote.artery.ArteryTransport(akka://server)] Remoting started; listening on address: [akka://server@192.168.0.250:5001] with UID [-2663186266051514585]
但是当我尝试启动客户端时,出现以下错误:
[ERROR] [07/04/2017 14:09:05.250] [client-akka.actor.default-dispatcher-10] [akka://server@192.168.0.250:5001/] swallowing exception during message send
io.aeron.exceptions.RegistrationException: Insufficient usable storage for new log of length=50332096 in /dev/shm (shm)
at io.aeron.ClientConductor.onError(ClientConductor.java:285)
at io.aeron.DriverListenerAdapter.onMessage(DriverListenerAdapter.java:79)
at org.agrona.concurrent.broadcast.CopyBroadcastReceiver.receive(CopyBroadcastReceiver.java:100)
at io.aeron.DriverListenerAdapter.pollMessage(DriverListenerAdapter.java:59)
at io.aeron.ClientConductor.doWork(ClientConductor.java:422)
at io.aeron.ClientConductor.awaitResponse(ClientConductor.java:447)
at io.aeron.ClientConductor.addPublication(ClientConductor.java:177)
at io.aeron.Aeron.addPublication(Aeron.java:165)
at akka.remote.artery.AeronSink$$anon.<init>(AeronSink.scala:103)
at akka.remote.artery.AeronSink.createLogicAndMaterializedValue(AeronSink.scala:100)
at akka.stream.impl.GraphStageIsland.materializeAtomic(PhasedFusingActorMaterializer.scala:627)
at akka.stream.impl.PhasedFusingActorMaterializer.materialize(PhasedFusingActorMaterializer.scala:458)
at akka.stream.impl.PhasedFusingActorMaterializer.materialize(PhasedFusingActorMaterializer.scala:420)
at akka.stream.impl.PhasedFusingActorMaterializer.materialize(PhasedFusingActorMaterializer.scala:415)
at akka.stream.scaladsl.RunnableGraph.run(Flow.scala:439)
at akka.remote.artery.Association.akka$remote$artery$Association$$runOutboundOrdinaryMessagesStream(Association.scala:570)
at akka.remote.artery.Association.runOutboundStreams(Association.scala:510)
at akka.remote.artery.Association.associate(Association.scala:502)
at akka.remote.artery.AssociationRegistry.association(Association.scala:763)
at akka.remote.artery.ArteryTransport.association(ArteryTransport.scala:932)
at akka.remote.artery.ArteryTransport.send(ArteryTransport.scala:918)
at akka.remote.RemoteActorRef.$bang(RemoteActorRefProvider.scala:563)
at akka.actor.ActorRef.tell(ActorRef.scala:124)
at akka.actor.ActorSelection$.rec(ActorSelection.scala:250)
at akka.actor.ActorSelection$.deliverSelection(ActorSelection.scala:254)
at akka.actor.ActorSelection.tell(ActorSelection.scala:45)
at actors.ClientActor.<init>(ClientActor.java:21)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at akka.util.Reflect$.instantiate(Reflect.scala:44)
at akka.actor.NoArgsReflectConstructor.produce(IndirectActorProducer.scala:105)
at akka.actor.Props.newActor(Props.scala:213)
at akka.actor.ActorCell.newActor(ActorCell.scala:563)
at akka.actor.ActorCell.create(ActorCell.scala:589)
at akka.actor.ActorCell.invokeAll(ActorCell.scala:462)
at akka.actor.ActorCell.systemInvoke(ActorCell.scala:484)
at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:282)
at akka.dispatch.Mailbox.run(Mailbox.scala:223)
at akka.dispatch.Mailbox.exec(Mailbox.scala:234)
at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
我也尝试用这些发送消息 "ActorSelection paths":
"akka://server@192.168.0.250:5001/user/server-process" "akka://server@localhost:5001/user/server-process" "akka://server@192.168.0.250:10001/user/server-process" "akka://server@localhost:10001/user/server-process"
但错误仍然出现。
同样重要的是要澄清,服务器演员的演员路径是:
akka://server/user/server-process
少了什么?我正在使用 akka 2.5.3 版本...
谢谢。
我不太确定 Akka 规范与绑定寻址的工作原理。但我的猜测是 bind.hostname
是实际 IP 或由它将侦听的主机名解析的 IP。在这种情况下,localhost
转换为 127.0.0.1
,这意味着容器将只接受 127.0.0.1
上的连接。
尝试将 bind.hostname
设置为 0.0.0.0
。这将允许来自容器外部 IP 地址的连接(从主机通过端口 5001)。
尝试将 /dev/shm
卷的大小设置得更大。在 docker-compose 文件中,您可以简单地添加此选项:shm_size: 500M
。此卷是 aeron 用来缓冲消息的共享内存 space。