第90讲:基于Scala的Actor之上的分布式并发消息驱动框架Akka初体验学习笔记

来源:互联网 发布:转换成淘宝客链接 编辑:程序博客网 时间:2024/05/18 22:41

90讲:基于ScalaActor之上的分布式并发消息驱动框架Akka初体验学习笔记

akka在业界使用非常广泛

spark背后就是由akka驱动的

要写消息驱动的编程模型都首推akka

下面将用30讲讲解akka

本讲主要讲两部分内容:

1.akka的重大意义

2.akkascalaactor

 

Spark源码中使用akka使用鉴赏:

spark中有200行左右代码封装了akka的使用

spark是分布式的计算框架,有masterslave主从节点通信时都是使用akka

客户端提交程序时也是使用akka。所以如果要掌握spark必须要理解和掌握akka

private def initializeEventProcessActor(){

  //blocking the thread until supervisor is started,

  //which ensures eventProcessActor is not null before any job is submitted

  implicit val timeout = Timeout(30 seconds)

  val initEventActorReply = 

    dagSchedulerActorSupervisor ? Props(new DAGSchedulerEventProcessActor(this))

    eventProcessActor = Await.result(initEventActorReply,timeout.duration).asInstanceOf[ActorRef]

  //用问号等待另一个actor的执行结果。!是立即发送消息。

}

initializeEventProcessActor()

//called by TashScheduler to report task's starting.

  def taskStarted(task: Task[_],taskInfo: TaskInfo) {

    eventProcessActor ! BeginEvent(task,taskInfo)

}

//Called to report that a task has completed and results are being fetched remotely.

def taskGettingResult(taskInf: TaskInfo){

  eventProcessActor ! GettingResultEvent(taskInfo)

}

 

Scalable real-time transaction processing

//transaction processing:支持分布式事务

We believe that writing correct concurrent, fault-tolerant and scalable applications is too hard. Most of the time it's

because we are using the wrong tools and the wrong level of abstraction. Akka is here to change that. Using the Actor Model

we raise the abstraction level and provide a better platform to build scalable,resilient and responsive

applications-see the Reactive Manifesto for more details.For fault-tolerance we adopt the "let it crash" model

which the telecom industry has used with great success to build applications that self-heal and systems that never stop.

Actors also provide the abstaction for transparent distribution and the basis for truly scalable and fault-tolerant applications.

Akka is Open Source and available under the Apache 2 License.

 

spark广泛运用在金融,实时在线交易等场合。

transparent distribution:位置透明

 

 

Akka provides scalable real-time transaction processing.

 

Akka is an unified runtime and programming model for:

 

Scale up (Concurrency)

Scale out (Remoting)

Fault tolerance

One thing to learn and admin, with high cohesion and coherent semantics.

 

Akka is a very scalable piece of software, not only in the context 

of performance but also in the size of applications it is useful for.

 The core of Akka, akka-actor, is very small and easily dropped into

 an existing project where you need asynchronicity and lockless 

concurrency without hassle.

 

You can choose to include only the parts of akka you need in your 

application and then there's the whole package, the Akka 

Microkernel, which is a standalone container to deploy your Akka 

application in. With CPUs growing more and more cores every cycle, 

Akka is the alternative that provides outstanding performance 

even if you're only running it on one machine. Akka also 

supplies a wide array of concurrency-paradigms, allowing users 

to choose the right tool for the job.

 

What's a good use-case for Akka?

We see Akka being adopted by many large organizations in a big range of industries:

 

Investment and Merchant Banking

Retail

Social Media

Simulation

Gaming and Betting

Automobile and Traffic Systems

Health Care

Data Analytics

and much more. Any system with the need for high-throughput and 

low latency is a good candidate for using Akka.

 

Actors let you manage service failures (Supervisors), 

load management (back-off strategies, timeouts and 

processing-isolation), as well as both horizontal and vertical 

scalability (add more cores and/or add more machines).

 

Here's what some of the Akka users have to say about how 

they are using Akka: 

http://stackoverflow.com/questions/4493001/good-use-case-for-akka

 

All this in the ApacheV2-licensed open source project.

 

 

akka的每个actor有自己的状态和行为。就是属性和方法

不断循环自己的邮箱,启动后就循环。

其他actor就可以给他发消息,他就可以处理邮件。

akka基于actor,本身有ActorSystemactor交互时用ActorRef是代理模式。

本讲只是预览一下akka的内容。

 

以上内容是从王家林老师DT大数据课程第90讲的学习笔记。
DT大数据微信公众账号:DT_Spark  

王家林老师QQ:1740415547 

王家林老师微信号:18610086859
scala90讲视频观看链接:
http://yun.baidu.com/s/1Ffqe6
我的百度网盘共享的DT大数据梦工厂王家林老师第1-90讲的视频内容:http://pan.baidu.com/s/1qWK9CMo

今日【DT大数据梦工厂视频】《第90讲:基于Scala的Actor之上的分布式并发消息驱动框架Akka初体验》
土豆视频:http://www.tudou.com/programs/view/wMRFwzk3u4Q/ 
优酷视频:http://v.youku.com/v_show/id_XMTMxMzkyODE1Mg==.html?from=y1.7-1.2 
腾讯视频:http://v.qq.com/page/k/x/2/k0163ov8kx2.html 
 (DT大数据梦工厂scala的所有视频、PPT和代码在百度云盘的链接:http://url.cn/fSFPjS)

 

0 0
原创粉丝点击