博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Akka的好用例[关闭]
阅读量:2290 次
发布时间:2019-05-09

本文共 8477 字,大约阅读时间需要 28 分钟。

本文翻译自:

I have heard lots of raving about framework (Java/Scala service platform), but so far have not seen many actual examples of use cases it would be good for. 我听说过很多关于框架(Java / Scala服务平台)的狂热,但到目前为止还没有看到很多用例的实际例子。 So I would be interested in hearing about things developers have used it succesfully. 所以我有兴趣听听开发人员成功使用它的事情。

Only one limitation: please do not include case of writing a chat server. 只有一个限制:请不要包括编写聊天服务器的情况。 (why? since this has been overused as an example for lots of similar things) (为什么?因为这被过度使用作为许多类似事物的一个例子)


#1楼

参考:


#2楼

I was trying out my hands on Akka (Java api). 我正在尝试Akka(Java api)。 What I tried was to compare Akka's actor based concurrency model with that of plain Java concurrency model (java.util.concurrent classes). 我试过的是将Akka基于actor的并发模型与普通Java并发模型(java.util.concurrent类)进行比较。

The use case was a simple canonical map reduce implementation of character count. 用例是一个简单的规范映射,减少了字符数的实现。 The dataset was a collection of randomly generated strings (400 chars in length), and calculate the number of vowels in them. 数据集是随机生成的字符串的集合(长度为400个字符),并计算其中的元音数量。

For Akka I used a BalancedDispatcher(for load balancing amongst threads) and RoundRobinRouter (to keep a limit on my function actors). 对于Akka,我使用了BalancedDispatcher(用于线程之间的负载平衡)和RoundRobinRouter(以限制我的函数actor)。 For Java, I used simple fork join technique (implemented without any work stealing algorithm) that would fork map/reduce executions and join the results. 对于Java,我使用了简单的fork join技术(没有任何工作窃取算法实现),它会分叉映射/减少执行并加入结果。 Intermediate results were held in blocking queues to make even the joining as parallel as possible. 中间结果保存在阻塞队列中,以使连接尽可能并行。 Probably, if I am not wrong, that would mimic somehow the "mailbox" concept of Akka actors, where they receive messages. 也许,如果我没有错,那将模仿Akka演员的“邮箱”概念,在那里他们收到消息。

Observation: Till medium loads (~50000 string input) the results were comparable, varying slightly in different iterations. 观察:直到中等载荷(~50000弦输入),结果具有可比性,在不同的迭代中略有不同。 However, as I increased my load to ~100000 it would hang the Java solution. 但是,当我将负载增加到~100000时,它会挂起Java解决方案。 I configured the Java solution with 20-30 threads under this condition and it failed in all iterations. 在这种情况下,我使用20-30个线程配置了Java解决方案,并且在所有迭代中都失败了。

Increasing the load to 1000000, was fatal for Akka as well. 将负荷增加到1000000对Akka来说也是致命的。 I can share the code with anyone interested to have a cross check. 我可以与任何有兴趣进行交叉检查的人分享代码。

So for me, it seems Akka scales out better than traditional Java multithreaded solution. 所以对我来说,似乎Akka比传统的Java多线程解决方案更好。 And probably the reason is the under the hood magic of Scala. 也许原因在于Scala的引擎盖下魔力。

If I can model a problem domain as an event driven message passing one, I think Akka is a good choice for the JVM. 如果我可以将问题域建模为事件驱动的消息传递,我认为Akka是JVM的一个很好的选择。

Test performed on: Java version:1.6 IDE: Eclipse 3.7 Windows Vista 32 bit. 测试执行于:Java版本:1.6 IDE:Eclipse 3.7 Windows Vista 32位。 3GB ram. 3GB内存。 Intel Core i5 processor, 2.5 GHz clock speed 英特尔酷睿i5处理器,2.5 GHz时钟速度

Please note, the problem domain used for the test can be debated and I tried to be as much fair as my Java knowledge allowed :-) 请注意,用于测试的问题域可以辩论,我试图尽可能公平,因为我的Java知识允许:-)


#3楼

We use Akka to process REST calls asynchronously - together with async web server (Netty-based) we can achieve 10 fold improvement on the number of users served per node/server, comparing to traditional thread per user request model. 我们使用Akka异步处理REST调用 - 与异步Web服务器(基于Netty)一起,与每个用户请求模型的传统线程相比,我们可以将每个节点/服务器服务的用户数量提高10倍。

Tell it to your boss that your AWS hosting bill is going to drop by the factor of 10 and it is a no-brainer! 告诉你的老板,你的AWS托管账单将减少10倍,这是一个明智的做法! Shh... dont tell it to Amazon though... :) 嘘......不要告诉亚马逊...... :)


#4楼

We use Akka in spoken dialog systems ( ). 我们在口语对话系统( )中使用Akka。 Both internally and externally. 内部和外部。 In order to simultaneously run a lot of telephony channels on a single cluster node it is obviously necessary to have some multithreading framework. 为了在单个集群节点上同时运行许多电话通道,显然需要有一些多线程框架。 Akka works just perfect. Akka的作品非常完美。 We have previous nightmare with the java-concurrency. 我们之前曾经遇到过java-concurrency的噩梦。 And with Akka it is just like a swing — it simply works. 和Akka一样,它就像一个秋千 - 它只是起作用。 Robust and reliable. 坚固可靠。 24*7, non-stop. 24 * 7,不停。

Inside a channel we have real-time stream of events that are processed in parallel. 在频道内部,我们拥有并行处理的实时事件流。 In particular: - lengthy automatic speech recognition — is done with an actor; 特别是: - 冗长的自动语音识别 - 由演员完成; - audio output producer that mixes a few audio sources (including synthesized speech); - 混合少量音频源(包括合成语音)的音频输出制作者; - text-to-speech conversion is a separate set of actors shared between channels; - 文本到语音转换是在通道之间共享的一组独立的参与者; - semantic and knowledge processing. - 语义和知识处理。

To make interconnections of complex signal processing we use . 为了实现复杂信号处理的互连,我们使用 。 It has the benefit of compile-time checking of the DataFlow in the complex actor systems. 它具有复杂actor系统中DataFlow的编译时检查的好处。


#5楼

You can use Akka for several different kinds of things. 您可以将Akka用于几种不同的事情。

I was working on a website, where I migrated the technology stack to Scala and Akka. 我正在一个网站上工作,我将技术堆栈迁移到Scala和Akka。 We used it for pretty much everything that happened on the website. 我们将它用于网站上发生的所有事情。 Even though you might think a Chat example is bad, all are basically the same: 即使您可能认为聊天示例不好,但所有内容基本相同:

  • Live updates on the website (eg views, likes, ...) 网站上的实时更新(例如观看次数,喜欢......)
  • Showing live user comments 显示实时用户评论
  • Notification services 通知服务
  • Search and all other kinds of services 搜索和所有其他类型的服务

Especially the live updates are easy since they boil down to what a Chat example ist. 特别是实时更新很容易,因为它们归结为聊天示例。 The services part is another interesting topic because you can simply choose to use remote actors and even if your app is not clustered, you can deploy it to different machines with ease. 服务部分是另一个有趣的主题,因为您可以简单地选择使用远程actor,即使您的应用程序没有群集,您也可以轻松地将其部署到不同的计算机上。

I am also using Akka for a PCB autorouter application with the idea of being able to scale from a laptop to a data center. 我还将Akka用于PCB自动布线应用,其理念是能够从笔记本电脑扩展到数据中心。 The more power you give it, the better the result will be. 你给它的力量越大,结果就越好。 This is extremely hard to implement if you try to use usual concurrency because Akka gives you also location transparency. 如果您尝试使用通常的并发性,这非常难以实现,因为Akka还为您提供了位置透明性。

Currently as a free time project, I am building a web framework using only actors. 目前作为一个空闲时间项目,我正在构建一个仅使用actor的Web框架。 Again the benefits are scalability from a single machine to an entire cluster of machines. 同样,好处是从单台机器到整个机器集群的可扩展性。 Besides, using a message driven approach makes your software service oriented from the start. 此外,使用消息驱动方法使您的软件服务从一开始就面向。 You have all those nice components, talking to each other but not necessarily knowing each other, living on the same machine, not even in the same data center. 你拥有所有那些漂亮的组件,彼此交谈但不一定彼此了解,生活在同一台机器上,甚至不在同一个数据中心。

And since Google Reader shut down I started with a RSS reader, using Akka of course. 自从Google Reader关闭后,我开始使用RSS阅读器,当然使用Akka。 It is all about encapsulated services for me. 这完全是关于我的封装服务。 As a conclusion: The actor model itself is what you should adopt first and Akka is a very reliable framework helping you to implement it with a lot of benefits you will receive along the way. 作为结论:演员模型本身就是你应该首先采用的,而Akka是一个非常可靠的框架,帮助你实现它,并带来很多好处。


#6楼

If you abstract the chat server up a level, then you get the answer. 如果您将聊天服务器抽象到一个级别,那么您将得到答案。

Akka provides a messaging system that is akin to Erlang's "let it crash" mentality. Akka提供的消息传递系统类似于Erlang的“让它崩溃”的心态。

So examples are things that need varying levels of durability and reliability of messaging: 所以示例是需要不同级别的持久性和消息传递可靠性的事物:

  • Chat server 聊天服务器
  • Network layer for an MMO MMO的网络层
  • Financial data pump 财务数据泵
  • Notification system for an iPhone/mobile/whatever app 适用于iPhone /手机/任何应用的通知系统
  • REST Server REST服务器
  • Maybe something akin to WebMachine (guess) 也许类似于WebMachine(猜测)

The nice things about Akka are the choices it affords for persistence, it's STM implementation, REST server and fault-tolerance. 关于Akka的好处是它为持久性提供的选择,它是STM实现,REST服务器和容错。

Don't get annoyed by the example of a chat server, think of it as an example of a certain class of solution. 不要被聊天服务器的例子弄得烦恼,把它想象成某类解决方案的例子。

With all their excellent documentation, I feel like a gap is this exact question, use-cases and examples. 凭借他们所有出色的文档,我觉得这个问题,用例和示例存在差距。 Keeping in mind the examples are non-trivial. 记住这些例子并非易事。

(Written with only experience of watching videos and playing with the source, I have implemented nothing using akka.) (仅根据观看视频和玩源的经验编写,我没有使用akka实现任何功能。)

转载地址:http://xncnb.baihongyu.com/

你可能感兴趣的文章