zoukankan      html  css  js  c++  java
  • akka cluster singleton

    cluster singleton 需要注意的一点是

    ClusterSingletonProxy 必须和 ClusterSingletonManager 一起工作

    尝试过通过 path 来获得 singleton actor 的 actorRef,但是结果和期望的不同,具体的表现是,在 main 方法中,创建完 singleton actor 后,无法通过 path 获得实例

    val system = ActorSystem("ClusterSystem", config)
    
    val singletonManager: Props = ClusterSingletonManager.props(Master.props(Duration(99, "second")), "active", PoisonPill, None)
    
    system.actorOf(singletonManager, "master")
    
    val res = system.actorOf(ClusterSingletonManager.props(Master.props(Duration(99, "second")), "active", PoisonPill, None), "master")
    
    
    val path = ActorPath.fromString("akka.tcp://ClusterSystem@127.0.0.1:2551/user/master/active")
    
    askSingletonActor(system, path)
    

      

    askSingletonActor 会报错,说找不到此 actor,但是 ClusterSingletonManager 的 actor 倒是找得到

    在 singleton actor 的内部通过 path 找自己就找得到

    正解是,通过 ClusterSingletonProxy 来寻找 singleton actor

    val singletonActor = system.actorOf(ClusterSingletonProxy.props(
            singletonPath = "/user/master/active",
            role = None),
            name = "consumerProxy")
          
    singletonActor ! ParentGreetings
    

      

    这种方式,总是能够找的到 singleton actor。

    对于一般的 actor,在 main 方法创建之后可以直接找到 actor

    此外,我在 actor 做了下测试,通过消息传递的方式,1 秒内 能够从 0 加到 4 million,而 for 循环,达到千万只用了不到 0.05 秒

  • 相关阅读:
    python 安装Crypto.Ciphe
    ProxyPool 爬虫代理IP池配置采坑
    2020渗透测试面试问题大全
    Windows Server 2016抓取明文密码
    应用安全 – 端口漏洞整理
    .net core docker+ gogs + jenkins 自动化部署
    .net HttpClient 回传实体帮助类
    .net list转树状结构
    ABP 临时禁用TenantId IsDelete过滤
    ABP 使用cache缓存
  • 原文地址:https://www.cnblogs.com/xinsheng/p/4616546.html
Copyright © 2011-2022 走看看