actor

Replacing bad performing workers in pool

无人久伴 提交于 2019-12-10 09:38:36
问题 I have a set of actors that are somewhat stateless and perform similar tasks. Each of these workers is unreliable and potentially low performing. In my design- I can easily spawn more actors to replace lazy ones. The performance of an actor is assessed by itself. Is there a way to make the supervisor/actor pool do this assessment, to help decide which workers are slow enough for me to replace? Or is my current strategy "the" right strategy? 回答1: I'm new to akka myself, so only trying to help,

Akka框架基本要点介绍

霸气de小男生 提交于 2019-12-10 07:12:06
Akka基于Actor模型,提供了一个用于构建可扩展的(Scalable)、弹性的(Resilient)、快速响应的(Responsive)应用程序的平台。本文基本上是基于Akka的官方文档(版本是2.3.12),通过自己的理解,来阐述Akka提供的一些组件或概念,另外总结了Akka的一些使用场景。 Actor 维基百科这样定义Actor模型: 在计算科学领域,Actor模型是一个并行计算(Concurrent Computation)模型,它把actor作为并行计算的基本元素来对待:为响应一个接收到的消息,一个actor能够自己做出一些决策,如创建更多的actor,或发送更多的消息,或者确定如何去响应接收到的下一个消息。 Actor是Akka中最核心的概念,它是一个封装了状态和行为的对象,Actor之间可以通过交换消息的方式进行通信,每个Actor都有自己的收件箱(Mailbox)。 通过Actor能够简化锁及线程管理,可以非常容易地开发出正确地并发程序和并行系统,Actor具有如下特性: 提供了一种高级抽象,能够简化在并发(Concurrency)/并行(Parallelism)应用场景下的编程开发 提供了异步非阻塞的、高性能的事件驱动编程模型 超级轻量级事件处理(每GB堆内存几百万Actor) 实现一个Actor,可以继承特质akka.actor.Actor

Akka Remote Actor_简单示例二

怎甘沉沦 提交于 2019-12-10 06:59:42
Akka Remote Actor_简单示例二 在上一篇文章中, http://my.oschina.net/xinxingegeya/blog/369445 使用Patterns.ask方法来与remote actor交互,还有没有另一种方式与remote actor交互?那就是使用 remote actor path,得到ActorSelection ,从而和remote actor交互。 那么先来了解一下remote actor path的构成,如下, akka.<protocol>://<actorsystemname>@<hostname>:<port>/<actor path> 那么有上篇文章中remote actor的配置可知,其remote actor path为: akka.tcp://CalculatorWorkerSystem@127.0.0.1 :2552/user/CalculatorActor 示例代码如下, package com.usoft9; import akka.actor.ActorSelection; import akka.actor.ActorSystem; import akka.actor.Props; import akka.actor.UntypedActor; import com.typesafe.config

Akka2使用探索5(Typed Actors)

橙三吉。 提交于 2019-12-10 06:59:24
Akka 中的有类型 Actor 是 Active Objects 模式的一种实现. Smalltalk诞生之时,就已经缺省地将方法调用从同步操作发为异步派发。 有类型 Actor 由两 “部分” 组成, 一个public接口和一个实现, 如果你有 “企业级” Java的开发经验, 这对你应该非常熟悉。 对普通actor来说,你拥有一个外部API ( public接口的实例 ) 来将方法调用异步地委托给其实现类的私有实例。 有类型Actor相对于普通Actor的优势在于有类型Actor拥有静态的契约, 你不需要定义你自己的消息, 它的劣势在于对你能做什么和不能做什么进行了一些限制,比如 你不能使用 become/unbecome. 有类型Actor是使用 JDK Proxies 实现的,JDK Proxies提供了非常简单的api来拦截方法调用。 注意 和普通Akka actor一样,有类型actor也一次处理一个消息。 什么时候使用有类型的Actor 有类型的Actor很适合用在连接actor系统和非actor的代码,因为它可以使你能在外部编写正常的OO模式的代码。但切记不可滥用。 工具箱 返回有类型actor扩展 Returns the Typed Actor Extension TypedActorExtension extension = TypedActor.get

Akka2使用探索4(Actors)

╄→гoц情女王★ 提交于 2019-12-10 06:48:05
Actor模型为编写并发和分布式系统提供了一种更高的抽象级别。它将开发人员从显式地处理锁和线程管理的工作中解脱出来,使编写并发和并行式系统更加容易。 Akka Actor的API与Scala Actor类似,并且从Erlang中借用了一些语法。 Actor类的定义 定义一个Actor类需要继承UntypedActor,并实现onReceive方法。 Props Props是一个用来在创建actor时指定选项的配置类。 以下是使用如何创建Props实例的示例. Props props1 = new Props(); Props props2 = new Props(MyUntypedActor.class); Props props3 = new Props(new UntypedActorFactory() { public UntypedActor create() { return new MyUntypedActor(); } }); Props props4 = props1.withCreator(new UntypedActorFactory() { public UntypedActor create() { return new MyUntypedActor(); } }); 使用Props创建Actor Actor可以通过将 Props 实例传入 actorOf

Akka2使用探索1(Remoting)

筅森魡賤 提交于 2019-12-10 06:45:59
akka从1.2升级到现在的2.0.2后有了很大的改变。现在摸索一下如何使用。 Remoting可以方便地用于服务器之间通信。akka1.2可以使用clientActor.sendRequestReply将消息发送到服务器端,并且同步获取服务器端的返回消息。但是akka2已经不能这么用了,akka2使用tell方法给另一个Actor发消息。 tell有两个重载方法: /** * Sends the specified message to the sender, i.e. fire-and-forget semantics.<p/> * <pre> * actor.tell(message); * </pre> */ final def tell(msg: Any): Unit = this.!(msg)(null: ActorRef) 只发送,不管其他,也不接收相应。actor.tell(msg)----给actor发送msg消息 /** * Java API. <p/> * Sends the specified message to the sender, i.e. fire-and-forget * semantics, including the sender reference if possible (not supported on * all senders).

Does a wait on Scala Future block thread?

巧了我就是萌 提交于 2019-12-10 03:39:34
问题 When I wait for result of Scala Future, does it behave more like receive , or like react , i.e. does it block a thread, or schedules a continuation after result if available? 回答1: Yes, in stdlib it blocks the thread, and synchronously waits for results. If you want to apply continuation-passing style to futures, you'd have to use Akka or Scalaz that allow adding hooks on futures completion straight from the box. Akka: val f1 = Future { Thread.sleep(1000); "Hello" + "World" } val f2 = f1 map {

Android开发小札(一)

二次信任 提交于 2019-12-10 02:20:11
这个小札记主要记录了开发中遇到的问题和解决方案,还有一些源码技巧。 • ImageView方法setImageUri导致OOM 获取到本地图片的Uri以后直接通过setImageUri导致了OutOfMemoryError 分析: 使用setImageUri是直接对uri对应的图片进行加载的,如果图片过大,就会造成OOM 解决: 使用Glide加载,或者对图片进行压缩处理后再设置 • 一个HashCode的生成方法 public class Actor { private final int id ; private final String name ; private final int rating ; private final int yearOfBirth ; public Actor ( int id , String name , int rating , int yearOfBirth ) { this . id = id ; this . name = name ; this . rating = rating ; this . yearOfBirth = yearOfBirth ; } // getter @Override public boolean equals ( Object o ) { if ( this == o ) return true ;

How to limit concurrency when using actors in Scala?

一世执手 提交于 2019-12-10 01:52:33
问题 I'm coming from Java, where I'd submit Runnable s to an ExecutorService backed by a thread pool. It's very clear in Java how to set limits to the size of the thread pool. I'm interested in using Scala actors, but I'm unclear on how to limit concurrency. Let's just say, hypothetically, that I'm creating a web service which accepts "jobs". A job is submitted with POST requests, and I want my service to enqueue the job then immediately return 202 Accepted — i.e. the jobs are handled

Akka的Actor层级结构《seven》译

时间秒杀一切 提交于 2019-12-09 18:25:10
示例简介 在写散文时,最难的部分往往是编写前几句话。在开始构建Akka系统时,有一种类似的“空白画布”的感觉。你可能想知道:哪个应该是第一个Actor?它应该住在哪里?它该怎么办?幸运的是 - 与散文不同,已建立的最佳实践可以指导我们完成这些初步步骤。在本指南的其余部分,我们将研究一个简单的Akka应用程序的核心逻辑,向您介绍Actor并向您展示如何使用它们制定解决方案。该示例演示了可帮助您启动Akka项目的常见模式。 准备部分 您应该已经按照 Akka Quickstart with Java guide 指南中的说明下载并运行Hello World示例。您将使用它作为种子项目并添加本教程中描述的功能。 IoT例子 在本教程中,我们将使用Akka构建物联网(IoT)系统的一部分,该系统报告来自客户家中安装的传感器设备的数据。该示例着重于温度读数。目标用例允许客户登录并查看他们家中不同区域的最后报告温度。您可以想象这样的传感器还可以收集相对湿度或其他有趣的数据,并且应用程序可能支持读取和更改设备配置,甚至可能在传感器状态超出特定范围时警告房主。 在真实系统中,应用程序将通过移动应用程序或浏览器向客户公开。本指南仅关注用于存储将通过网络协议调用的温度的核心逻辑,例如HTTP。它还包括编写测试,以帮助您获得测试Actor的舒适和熟练。 教程应用程序包含两个主要组件: 设备数据收集: -