• 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 秒

  • 相关阅读:
    操作系统-多进程图像
    025.Kubernetes掌握Service-SVC基础使用
    Linux常用查看版本指令
    使用动态SQL处理table_name作为输入参数的存储过程(MySQL)
    INTERVAL 用法 mysql
    sql server编写archive通用模板脚本实现自动分批删除数据【填空式编程】
    docker部署redis集群
    Ubuntu1804下安装Gitab
    Bash脚本编程学习笔记06:条件结构体
    KVM虚拟化基础
  • 原文地址:https://www.cnblogs.com/xinsheng/p/4616546.html
Copyright © 2020-2023  润新知