Akka深入浅出实战经典

合集下载

Akka之初识与API操作实例

Akka之初识与API操作实例

Akka之初识与API操作实例Akka 是一个用 Scala 编写的库,用于简化编写容错的、高可伸缩性的 Java 和 Scala 的 Actor 模型应用。

Akka是一个开发库和运行环境,可以用于构建高并发、分布式、可容错、事件驱动的基于JVM的应用。

使构建高并发的分布式应用更加容易。

Akka可以以两种不同的方式来使用以库的形式:在web应用中使用,放到WEB-INF/lib 中或者作为一个普通的Jar包放进classpath。

以微内核的形式:你可以将应用放进一个独立的内核。

自己有一个main类来初始化Actor系统。

Akka平台竞争力Akka提供可扩展的实时事务处理。

Akka是一个运行时与编程模型一致的系统,为以下目标设计:- 垂直扩展(并发)- 水平扩展(远程调用)- 高容错Akka的几大特性:1)易于构建并行和分布式应用(Simple Concurrency & Distribution)Akka在设计时采用了异步通讯和分布式架构,并对上层进行抽象,如Actors、Futures ,STM等。

2)可靠性(Resilient by Design)系统具备自愈能力,在本地/远程都有监护。

3)高性能(High Performance)在单机中每秒可发送50000000个消息。

内存占用小,1GB内存中可保存2500000个actors。

4)弹性,无中心(Elastic — Decentralized)自适应的负责均衡,路由,分区,配置5)可扩展(Extensible)可以使用Akka 扩展包进行扩展。

在Akka的世界里,只有一个内容需要学习和管理,具有高内聚和高一致的语义。

Akka是一种高度可扩展的软件,这不仅仅表现在性能方面,也表现在它所适用的应用的大小。

Akka的核心,Akka-actor是非常小的,可以非常方便地放进你的应用中,提供你需要的异步无锁并行功能,不会有任何困扰。

你可以任意选择Akka的某些部分集成到你的应用中,也可以使用完整的包——Akka 微内核,它是一个独立的容器,可以直接部署你的Akka应用。

基于AKKA的后台应用开发手册

基于AKKA的后台应用开发手册

基于AKKA的后台应用开发手册版本<>修订历史基于AKKA的后台应用开发手册 (5)1 概述 (5)1.1前言 (5)1.2目的 (5)1.3范围 (5)1.4术语和缩写语 (6)2 Actor的大体开发 (7)2.1创建简单Actor (7)2.2创建带参数构造器Actor (8)2.3Actor停止监视 (8)2.4Actor生命周期控制 (9)2.5Actor未概念消息处置 (9)2.6Actor消息发送 (10)2.7Actor消息接收超时 (11)2.8Actor停止 (11)2.9变换Actor 消息匹配功能 (12)2.10Actor消息栈 (12)2.11Actor匹配消息功能扩展 (13)2.12Actor容错机制 (14)3 Actor DSL (16)3.1创建DSL Actor (16)3.2切换DSL Actor 消息匹配功能 (16)3.3DSL Actor生命周期控制 (17)3.4DSL Actor异样监控 (17)3.5DSL Actor消息栈 (17)4 Typed Actor (19)4.1创建Typed Actor (19)4.2Typed Actor代理对象 (19)4.3Typed Actor停止 (20)4.4Typed Actor其它 (20)5 Actor日记 (22)5.1Actor Log大体功能 (22)6 Actor任务 (23)6.1Actor schedule大体功能 (23)7 Actor Future利用 (24)7.1Future和Actor配合利用 (24)7.2直接利用Future (24)7.3Future连接方式 (25)7.4Future和for配合利用 (25)7.5大量Future配合利用 (25)7.6Future回调 (26)7.7Dataflow并发 (27)8 消息总线实例 (29)8.1消息总线的功能和作用 (29)8.2PAAS平台架构 (29)8.3消息总线类 (30)8.4消息总线时序图 (31)8.5消息总线客户代码挪用机制 (33)8.6消息总线服务代码实现机制 (34)8.7PAAS平台消息概念机制 (34)8.8PAAS平台异样概念机制 (35)8.9PAAS平台包结构 (35)9 注意事项 (36)10 代码规范 (37)11 总结和展望 (39)12 附件代码 (40)13 参考资料 (52)基于AKKA的后台应用开发手册1概述1.1前言随着计算机硬件技术和网络技术的飞速发展,计算机拥有愈来愈多数量的内核,散布式技术和集群技术的成熟使得一个应用程序可以被分块运行在多个独立的计算机上(可能安装不同的操作系统),这些技术使得程序可以真正的并行运行。

整合KAFKA+Flink实例(第一部分,趟坑记录)

整合KAFKA+Flink实例(第一部分,趟坑记录)

整合KAFKA+Flink实例(第⼀部分,趟坑记录)2017年后,⼀⼤波⽹络喧嚣,说流式处理如何⽜叉,如何⾼⼤上,抱歉,⼯作满负荷,没空玩那个;今年疫情隔离在家,⽆聊,开始学习 KAFKA+Flink ,⽬前的打算是⽤爬⾍抓取⽹页数据,传递到Kafka中,再⽤Flink计算。

个⼈性格原因,我不愿意过分沉迷于纸质或者电⼦教程材料,也不是特别喜欢⽹上某些培训机构已经过时了的所谓培训视频,喜欢动⼿直接写代码,所以简单翻看⼀点PDF教程,看了两集“培训视频”,也没说Kafka、flink两组件咋结合使⽤,不耐烦,直接开码(码农的糙性);之前我写过的随笔已经有在windows上装Kafka、flink组件了,之前写了⼀个⼊门的Kafka使⽤代码;算是有简单的 Kafka使⽤成功案例;从昨天开始,我开始重新码代码;我先叨逼叨⼏句,顺便把趟坑的过程⼀并写上,后续我会把相关代码以及整体思路,整理好后,⼀并再发出来。

⼀叨逼叨⽹上的KAFKA+Flink 的例⼦百分之90都是读取⽂本⽂件,或者弄个循环10000次,查内存数据,这两种案例,来讲解Flink的处理机制;我迅速浏览代码后,忍俊不禁,为什么做10000次的循环,超过10000次就不跑了?这是什么应⽤场景?有⼈说,做⼀个while(true)循环不就得了,是,可以,还是为了达到写例⼦⽽写代码;请问,如果你⽤了⽆限循环,某天⽤户说,我临时决定,暂停下,过会再跑,你怎么弄?停掉整个应⽤?有⼈⼜会说,接⼊前端信号就⾏。

因为应⽤场景决定了应⽤的架构、功能以及开发的⽅向,对此我不想抬杠,这个话题就到此结束吧。

⼆接着叨逼叨⼤多⽹友传递对象时,都是⾃⼰⼿动序列化对象,甚⾄直接⽤字符串,中间⽤逗号分隔;例如1 String value = String.format("%d,%s,%d", System.currentTimeMillis(), "machine-1", currentMemSize());2 System.out.println("发送数据-->"+value);3 producer.send(new ProducerRecord<Object, String>("demo", value), new Callback() {4 @Override5public void onCompletion(RecordMetadata metadata, Exception exception) {6if (exception != null) {7 System.out.println("Failed to send message with exception " + exception);8 }9 }10 });我看了,就想问,你这对象挺简单的哈,要是字符串对象中的值,本⾝就有逗号,你咋办?另外,有些对象属性类型复杂,既有String,⼜有 BigDecimal ,甚⾄⾥⾯有嵌⼊ ArrayList对象,你这咋整啊?不序列化了?或者都toString了,再整⼀起??三反省⽹友⼤多使⽤对象 FlinkKafkaConsumer011 来接收处理Flink数据,说实话,我挺不屑的,感觉都在互相抄代码,没劲;我第⼀次弄的时候,⽤的是 FlinkKafkaConsumer082 ,我误以为082⽐011版本⾼,直到我在某⼀阶段全部报有关 FlinkKafkaConsumer082 的错误时,我才开始意识到我的错误;Apache组织命名对象的版本时,真⼼会让我混乱,难道82不⽐11⼤吗?难道版本号不是越⼤越新吗?最后,事实我告诉⾃⼰,真的,真的不是!所以在抄别⼈代码前,还是⾃⼰去官⽹确定版本吧,甚⾄都不能信阿⾥的maven站,当以 artifactId 名称来搜索排序时,⼀定要多往下拉数据看,阿⾥的排序不是最⾼版本在最前⾯,往往既不在最前⾯,也不在最后⾯;四处理异常截⽌到现在,我先写取Kafka数据输出到本地⽂本,使⽤了对象 SingleOutputStreamOperator 但是出现异常:17:48:59.084 [main] DEBUG ty.util.internal.InternalThreadLocalMap - ty.threadLocalMap.stringBuilder.initialSize: 102417:48:59.084 [main] DEBUG ty.util.internal.InternalThreadLocalMap - ty.threadLocalMap.stringBuilder.maxSize: 409617:48:59.558 [main] WARN org.apache.flink.runtime.webmonitor.WebMonitorUtils - Log file environment variable 'log.file' is not set.17:48:59.558 [main] WARN org.apache.flink.runtime.webmonitor.WebMonitorUtils - JobManager log files are unavailable in the web dashboard. Log file location not found in environment variable 'log.file' or configuration key 'Key: 'web.log.path' , de 17:48:59.646 [main] DEBUG org.apache.flink.runtime.dispatcher.DispatcherRestEndpoint - Failed to load web based job submission extension.org.apache.flink.util.FlinkException: The module flink-runtime-web could not be found in the class path. Please add this jar in order to enable web based job submission.at org.apache.flink.runtime.webmonitor.WebMonitorUtils.loadWebSubmissionExtension(WebMonitorUtils.java:192)at org.apache.flink.runtime.dispatcher.DispatcherRestEndpoint.initializeHandlers(DispatcherRestEndpoint.java:98)at org.apache.flink.runtime.rest.RestServerEndpoint.start(RestServerEndpoint.java:141)at ponent.AbstractDispatcherResourceManagerComponentFactory.create(AbstractDispatcherResourceManagerComponentFactory.java:161)at org.apache.flink.runtime.minicluster.MiniCluster.createDispatcherResourceManagerComponents(MiniCluster.java:378)at org.apache.flink.runtime.minicluster.MiniCluster.start(MiniCluster.java:313)at org.apache.flink.streaming.api.environment.LocalStreamEnvironment.execute(LocalStreamEnvironment.java:114)at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.execute(StreamExecutionEnvironment.java:1507)at com.kafkastudy.kafka01.FlinkDealWithKafka.main(FlinkDealWithKafka.java:93)17:48:59.808 [main] DEBUG ty.util.internal.PlatformDependent - Platform: Windows17:48:59.814 [main] DEBUG ty.util.internal.PlatformDependent0 - ty.noUnsafe: false17:48:59.815 [main] DEBUG ty.util.internal.PlatformDependent0 - Java version: 817:48:59.822 [main] DEBUG ty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available17:48:59.826 [main] DEBUG ty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available17:48:59.830 [main] DEBUG ty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available17:48:59.834 [main] DEBUG ty.util.internal.PlatformDependent0 - direct buffer constructor: available17:48:59.838 [main] DEBUG ty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true17:48:59.838 [main] DEBUG ty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java917:48:59.838 [main] DEBUG ty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.<init>(long, int): available17:48:59.839 [main] DEBUG ty.util.internal.PlatformDependent - sun.misc.Unsafe: available17:48:59.840 [main] DEBUG ty.util.internal.PlatformDependent - ty.tmpdir: C:\Users\ADMINI~1\AppData\Local\Temp (java.io.tmpdir)17:48:59.841 [main] DEBUG ty.util.internal.PlatformDependent - ty.bitMode: 64 (sun.arch.data.model)17:48:59.848 [main] DEBUG ty.util.internal.PlatformDependent - ty.maxDirectMemory: 1888485376 bytes17:48:59.849 [main] DEBUG ty.util.internal.PlatformDependent - ty.uninitializedArrayAllocationThreshold: -117:48:59.855 [main] DEBUG ty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available17:48:59.856 [main] DEBUG ty.util.internal.PlatformDependent - ty.noPreferDirect: false。

深入理解kafka核心设计与实践原理pdf

深入理解kafka核心设计与实践原理pdf

深入理解kafka核心设计与实践原理pdf 《深入理解Kafka核心设计与实践原理》是一本讲述Kafka技术实现原理和使用方法的书籍。

本书通过深入剖析Kafka的核心设计和实现原理,旨在帮助读者更好地理解和应用Kafka技术。

首先,本书介绍了Kafka的基本概念。

Kafka是一种分布式消息系统,广泛应用于大规模在线日志、流式处理、事件驱动架构等场景。

本书首先介绍了Kafka的概念和基本组件,包括生产者、消费者、主题、分区、副本等,帮助读者建立对Kafka的整体认知。

接着,本书详细介绍了Kafka的核心设计和实现原理。

首先,本书介绍了Kafka的存储机制。

Kafka使用一种高效的消息存储格式,可以实现高吞吐量和低延迟的消息读写。

本书深入解析了Kafka的消息存储机制,包括消息格式、磁盘存储结构、索引机制等。

此外,本书还介绍了Kafka的消息压缩和消息过期机制,帮助读者更好地理解和应用Kafka的存储技术。

其次,本书介绍了Kafka的分布式架构和高可用特性。

Kafka采用分布式存储和复制机制,可以实现高可靠性和数据冗余。

本书详细介绍了Kafka的分布式架构和副本机制,包括副本分配、副本同步、副本选举等。

此外,本书还介绍了Kafka的故障处理和性能调优技巧,帮助读者更好地应对Kafka的实际应用场景。

最后,本书介绍了Kafka的生态系统和应用实践。

Kafka作为一款开源的消息中间件,有着活跃的社区和丰富的生态系统。

本书介绍了Kafka的扩展性和灵活性,以及与其他流行开源技术的结合,如Hadoop、Spark、Flink等。

此外,本书还提供了一些Kafka的最佳实践和应用案例,帮助读者更好地应用Kafka技术。

总之,《深入理解Kafka核心设计与实践原理》是一本非常实用和深入的Kafka技术书籍。

通过本书的学习,读者可以更深入地了解Kafka的核心设计和实现原理,从而更好地应用和调优Kafka技术。

无论是初学者还是有经验的开发者,都可以从本书中获得收获和启发。

Akka的Actor模型及使用实例

Akka的Actor模型及使用实例

Akka的Actor模型及使⽤实例本⽂的绝⼤部分内容转载⾃rerun.me这⼀blog,⽼外写的东西就是好啊。

ACTORS介绍Anyone who has done multithreading in the past won't deny how hard and painful it is to manage multithreaded applications. Isaid manage because it starts out simple and it became a whole lot of fun once you start seeing performance improvements. However, it aches when you see that you don't have a easier way to recover from errors in your sub-tasks OR those zombie bugs that you find hard to reproduce OR when your profiler shows that your threads are spending a lot of time blocking wastefully before writing to a shared state.I prefer not to talk about how Java concurrency API and their collections made it better and easier because I am sure if you are here, you probably needed more control over the sub-tasks or simply because you don't like to write locks and synchronized blocks and would prefer a higher level of abstraction.In this series of Akka Notes, we would go through simple Akka examples to explore the various features that we have in the toolkit. WHAT ARE ACTORS?Treat Actors like People. People who don't talk to each other in person. They just talk through mails.Let's expand on that a bit.1. MESSAGINGConsider two persons - A wise Teacher and Student. The Student sends a mail every morning to the Teacher and the wise Teacher sends a wise quote back.Points to note :1. The student sends a mail. Once sent, the mail couldn't be edited. Talk about natural immutability.2. The Teacher checks his mailbox when he wishes to do so.3. The Teacher also sends a mail back (immutable again).4. The student checks the mailbox at his own time.5. The student doesn't wait for the reply. (no blocking)That pretty much sums up the basic block of the Actor Model - passing messages.2. CONCURRENCYNow, imagine there are 3 wise teachers and 3 students - every student sends notes to every other teacher. What happens then? Nothing changes actually. Everybody has their own mailbox. One subtle point to note here is this :By default, Mails in the mailbox are read/processed in the order they arrived.Internally, by default it is a . And since nobody waits for the mail to be picked up, it is simply a non-blocking message. (There area including bounded and priority based. In fact, we could build one ourself too)3. FAILOVERImagine these 3 teachers are from three different departments - History, Geography and Philosophy.History teachers replies with a note on an Event in the past, Geography teachers sends an Interesting Place and Philosophy teachers, a quote. Each student sends message to each teacher and gets responses. The student doesnt care which teacher in the department sends the reply back. What if one day, a teacher falls sick? There has to be at least one teacher handling the mails from the department. In this case, another teacher in the department steps up and does the job.Points to note :1. There could be a pool of Actors who does different things.2. An Actor could do something that causes an exception. It wouldn't be able to recover by itself. In which case a new Actor couldbe created in place of the old one. Alternatively, the Actor could just ignore that one particular message and proceed with the rest of themessages. These are called Directives and we'll discuss them later.4. MULTITASKINGFor a twist, let's assume that each of these teachers also send the exam score through mail too, if the student asks for it. Similarly, an the Actor could handle more than one type of message comfortably.5. CHAININGWhat if the student would like to get only one final consolidated trivia mail instead of three?We could do that too with Actors too. We could chain the teachers as a hierarchy. We'll come back to that later when we talk about Supervisors and revisit the same thought when we talk about Futures.As requested by Mohan, let's just try to map the analogy components with the the components in the Actor Model.Students and the Teachers becomes our Actors. The Email Inbox becomes the Mailbox component. The request and the response can't be modified. They are immutable objects. Finally, the MessageDispatcher component in Actor manages the mailbox and routes the messages to the respective Mailbox.ACTOR 消息机制From the of the Akka Notes, we saw a bird's eye view of Actors in the Akka Toolkit. In this second part of the Akka Notes, we'll look at the messaging part of Actors. As for the example, we would use the same Student-Teacher example that we discussed earlier.In this first part of Actor Messaging, we'll create the Teacher Actor and instead of the Student Actor, we'll use a main program called StudentSimulatorApp.REVISITING STUDENT-TEACHER IN DETAILLet's for now consider the message sent by the StudentSimulatorApp to the TeacherActor alone. When I say StudentSimulatorApp, I just mean a normal main program.The picture conveys this :(if the terms are overwhelming, don't worry, we'll go through them in detail)1. Student creates something called an ActorSystem2. It uses the ActorSystem to create something called as ActorRef. The QuoteRequest message is sent to the ActorRef (a proxy toTeacherActor)3. Actor ref passes the message along to a Dispatcher4. The Dispatcher enqueues the message in the target Actor's MailBox.5. The Dispatcher then puts the Mailbox on a Thread (more on that in the next section).6. The MailBox dequeues a message and eventually delegates that to the actual Teacher Actor's receive method.Like I said, don't worry about it. Let's look at each step in detail now. You can come back and revisit these five steps once we are done. THE STUDENTSIMULATORAPP PROGRAMWe would use this StudentSimulatorApp to bring up the JVM and initialize the ActorSystem.As we understand from the picture, the StudentSimulatorApp1. Creates an ActorSystem2. Uses the ActorSystem to create a proxy to the Teacher Actor (ActorRef)3. Sends the QuoteRequest message to the proxy.Let's focus on these three points alone now.1. 1. Creating an ActorSystemis the entry point into the ActorWorld. ActorSystems are through which you could create and stop Actors. Or even shutdown the entire Actor environment.On the other end of the spectrum, Actors are hierarchical and the ActorSystem is also similar to the ng.Object or scala.Any for all Actors -meaning, it is the root for all Actors. When you create an Actor using the ActorSystem's actorOf method, you create an Actor just below the ActorSystem.The code for initializing the ActorSystem looks likeval system=ActorSystem("UniversityMessageSystem")The UniversityMessageSystem is simply a cute name you give to your ActorSystem.1. 2. Creating a Proxy for TeacherActor?Let's consider the following snippet :val teacherActorRef:ActorRef=actorSystem.actorOf(Props[TeacherActor])The actorOf is the Actor creation method in ActorSystem. But, as you can see, it doesn't return a TeacherActor which we need. It returns something of type ActorRef.The ActorRef acts as a Proxy for the actual Actors. The clients do not talk directly with the Actor. This is Actor Model's way of avoiding direct access to any custom/private methods or variables in the TeacherActor or any Actor for that sake.To repeat, you send messages only to the ActorRef and it eventually reaches your actual Actor. You can NEVER talk to your Actor directly. People will hate you to death if you find some mean ways to do that.1. 3. Send a QuoteRequest to the ProxyIt's an one liner again. You just tell the QuoteRequest message to the ActorRef. The tell method in Actor is actually !. (there's also a tell method in ActorRef which just delegates the call back to !)//send a message to the Teacher ActorteacherActorRef!QuoteRequestThat's itIf you think I am lying, check the entire code of the StudentSimulatorApp below :STUDENTSIMULATORAPP.SCALApackage me.rerun.akkanotes.messaging.actormsg1import akka.actor.ActorSystemimport akka.actor.Propsimport akka.actor.actorRef2Scalaimport me.rerun.akkanotes.messaging.protocols.TeacherProtocol._object StudentSimulatorApp extends App{//Initialize the ActorSystemval actorSystem=ActorSystem("UniversityMessageSystem")//construct the Teacher Actor Refval teacherActorRef=actorSystem.actorOf(Props[TeacherActor])//send a message to the Teacher ActorteacherActorRef!QuoteRequest//Let's wait for a couple of seconds before we shut down the systemThread.sleep (2000)//Shut down the ActorSystem.actorSystem.shutdown()}Well, I cheated a little. You'll have to shutdown the ActorSystem or otherwise, the JVM keeps running forever. And I am making the main thread sleep for a little while just to give the TeacherActor to finish off its task. I know this sounds stupid. Don't worry about it. We'll write some neat testcases in the next part in order to avoid this hack.THE MESSAGEWe just told a QuoteRequest to the ActorRef but we didn't see the message class at all !!Here it comes :(It is a recommended practice to wrap your messages in a nice object for easier organization)TeacherProtocolpackage me.rerun.akkanotes.messaging.protocolsobject TeacherProtocol{case class QuoteRequest()case class QuoteResponse(quoteString:String)}As you know, the QuoteRequest is for the requests that come to the TeacherActor. The Actor would respond back with a QuoteResponse. DISPATCHER AND A MAILBOXThe ActorRef delegates the message handling functionality to the Dispatcher. Under the hood, while we created the ActorSystem andthe ActorRef, a Dispatcher and a MailBox was created. Let's see what they are about.MailBoxEver Actor has one MailBox (we'll see one special case later). Per our analogy, every Teacher has one mailbox too. The Teacher has to check the mailbox and process the message. In Actor world, it's the other way round - the mailbox, when it gets a chance uses the Actor to accomplish its work.Also the mailbox has a queue to store and process the messages in a FIFO fashion - a little different from our regular inbox where the most latest is the one at the top.Now, the dispatcherDispatcher does some really cool stuff. From the looks of it, the Dispatcher just gets the message from the ActorRef and passes it on to the MailBox. But there's one amazing thing happening behind the scenes :Dispatcher does some really cool stuff. From the looks of it, the Dispatcher just gets the message from the ActorRef and passes it on to the MailBox. But there's one amazing thing happening behind the scenes :The Dispatcher wraps an (ForkJoinPool or ThreadPoolExecutor). It executes the MailBox against this ExecutorService.Check out this snippet from theprotected[akka] override def registerForExecution(mbox: Mailbox, ...): Boolean = {...try {executorService execute mbox...}⽰例代码这是⼀套⽤于计算熵增益的代码,⽤在相似度检测和内容推荐领域,主要思想是通过Master Actor派发计算任务给Worker Actor完成计算任务后,发消息通知Master完成计算结果的综合⼯作,最后结果的展⽰由listener Actor完成。

深入浅出 OpenWhisk

深入浅出 OpenWhisk

F
T
2019/9/12
Serverless & OpenWhisk ©刘洪晔
OpenWhisk编程模型 – 高阶模型
W Web Action: • 公开的URL, 可以通过RestFul方式直接调用.
W
2019/9/12
Serverless & OpenWhisk ©刘洪晔
OpenWhisk编程模型 – 高阶模型
A Action:
用来响应和处理事件的代码
可以用多种语言来实现(例如: java, python, swift, nodejs等)
对于其他未支持语言可以用Docker打包制做执行黑盒来使用
可以将多个Action组合创建成序列, 从而增加灵活性与重用程 度
AA : =
A1 + A2 + A3
Serverless & OpenWhisk ©刘洪晔
为什么是事件驱动模型?
总在最正确的时间做最正确的事, 避免浪费.
2019/9/12
Serverless & OpenWhisk ©刘洪晔
事件驱动
任何事物都在产生事件;
2019/9/12
现实生活中
Serverless & OpenWhisk ©刘洪晔
Nginx – 对外公开暴露HTTP(S)服务的节点
Software-Defined-Services
(SDOSSS)
Identity / Access
DataBase
Comput e
Storage
Networ k
Serverless Functions :
部署单元 : 简单单一任务函数 没有需要配置的“后端服务器”

akka中askpattern.ask用法

akka中askpattern.ask用法

文章标题:深度解析Akka中Ask Pattern的用法在Akka框架中,Ask Pattern是一种常见的用法,它可以用于在Actor之间进行消息通信,并获取到被请求Actor的返回结果。

本文将深入探讨Akka中Ask Pattern的使用方法,并从简到繁地介绍其原理和实际应用。

1. 什么是Ask Pattern?在Akka框架中,Ask Pattern是一种用于向Actor发送消息并等待其返回结果的机制。

它通常使用actorRef.ask()方法来发送消息,并通过返回的Future来获取被请求Actor的返回结果。

2. Ask Pattern的基本用法在实际代码中,我们可以使用ask()方法发送消息,并使用Scala的for表达式来处理返回的Future。

例如:```scalaval result: Future[Result] = (actorRef ? Request).mapTo[Result] ```这段代码中,我们向actorRef发送了一个Request消息,并通过mapTo()方法将返回的Future转换为Result类型的结果。

这是Ask Pattern的基本用法,它可以帮助我们实现Actor之间的异步消息通信。

3. Ask Pattern的原理分析Ask Pattern的原理其实是通过一个中间人Actor来实现的,这个Actor通常被称为Ask Actor。

当我们使用ask()方法发送消息时,实际上是将消息发送给了Ask Actor,并在返回的Future中等待Ask Actor将结果返回。

这种机制可以帮助我们在不阻塞当前线程的情况下获取到被请求Actor的返回结果。

4. Ask Pattern的深入应用除了基本用法外,Ask Pattern还可以用于实现一些复杂的消息交互。

我们可以通过ask()方法发送消息给多个Actor,并通过Future.sequence()方法将它们的返回结果合并为一个Future。

akka原理

akka原理

akka原理Akka是一种基于Actor模型的开源分布式计算框架,用于构建高并发、可伸缩和容错的分布式应用程序。

本文将深入探讨Akka的原理和工作方式,以及它为什么成为构建分布式系统的首选框架。

一、什么是Actor模型Actor模型是一种并发计算模型,它通过将计算单元分解为独立的、可并发执行的Actor来实现并发性。

每个Actor都是一个独立的个体,它们之间通过消息传递进行通信。

Actor模型的核心思想是“一切皆为Actor”,每个Actor都有自己的状态和行为,并且可以并发地执行。

二、Akka的基本概念1. Actor:在Akka中,Actor是最基本的计算单元。

每个Actor都有一个唯一的标识符和一个邮箱,用于接收和处理消息。

Actor之间通过消息传递进行通信。

2. 消息传递:Akka使用消息传递作为Actor之间的通信机制。

消息是不可变的,它包含了发送者和接收者的信息,以及要执行的操作。

消息在不同的Actor之间通过邮箱进行传递。

3. 邮箱:每个Actor都有一个邮箱,用于接收和存储消息。

当一个消息到达邮箱时,Actor可以根据消息的内容来决定自己的下一步操作。

4. 分发器:Akka使用分发器来管理消息的接收和处理。

分发器负责将消息发送到目标Actor的邮箱,并确保消息按照顺序被处理。

5. 监管机制:Akka提供了监管机制来处理Actor的错误和故障。

当一个Actor发生错误时,它的父Actor可以选择重启、停止或继续处理消息。

三、Akka的工作原理1. Actor的创建和启动:在Akka中,Actor的创建和启动是由Actor系统负责的。

当一个Actor被创建时,它会被分配一个唯一的标识符并初始化。

然后,Actor系统会将该Actor添加到Actor 层次结构中,并将其邮箱注册到分发器中。

2. 消息的发送和接收:当一个Actor发送消息时,它会将消息发送到目标Actor的邮箱。

分发器负责将消息发送到目标Actor的邮箱,并确保消息按照顺序被处理。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

江西省南昌市2015-2016学年度第一学期期末试卷(江西师大附中使用)高三理科数学分析一、整体解读试卷紧扣教材和考试说明,从考生熟悉的基础知识入手,多角度、多层次地考查了学生的数学理性思维能力及对数学本质的理解能力,立足基础,先易后难,难易适中,强调应用,不偏不怪,达到了“考基础、考能力、考素质”的目标。

试卷所涉及的知识内容都在考试大纲的范围内,几乎覆盖了高中所学知识的全部重要内容,体现了“重点知识重点考查”的原则。

1.回归教材,注重基础试卷遵循了考查基础知识为主体的原则,尤其是考试说明中的大部分知识点均有涉及,其中应用题与抗战胜利70周年为背景,把爱国主义教育渗透到试题当中,使学生感受到了数学的育才价值,所有这些题目的设计都回归教材和中学教学实际,操作性强。

2.适当设置题目难度与区分度选择题第12题和填空题第16题以及解答题的第21题,都是综合性问题,难度较大,学生不仅要有较强的分析问题和解决问题的能力,以及扎实深厚的数学基本功,而且还要掌握必须的数学思想与方法,否则在有限的时间内,很难完成。

3.布局合理,考查全面,着重数学方法和数学思想的考察在选择题,填空题,解答题和三选一问题中,试卷均对高中数学中的重点内容进行了反复考查。

包括函数,三角函数,数列、立体几何、概率统计、解析几何、导数等几大版块问题。

这些问题都是以知识为载体,立意于能力,让数学思想方法和数学思维方式贯穿于整个试题的解答过程之中。

二、亮点试题分析1.【试卷原题】11.已知,,A B C 是单位圆上互不相同的三点,且满足AB AC →→=,则AB AC →→⋅的最小值为( )A .14-B .12-C .34-D .1-【考查方向】本题主要考查了平面向量的线性运算及向量的数量积等知识,是向量与三角的典型综合题。

解法较多,属于较难题,得分率较低。

【易错点】1.不能正确用OA ,OB ,OC 表示其它向量。

2.找不出OB 与OA 的夹角和OB 与OC 的夹角的倍数关系。

【解题思路】1.把向量用OA ,OB ,OC 表示出来。

2.把求最值问题转化为三角函数的最值求解。

【解析】设单位圆的圆心为O ,由AB AC →→=得,22()()OB OA OC OA -=-,因为1OA OB OC ===,所以有,OB OA OC OA ⋅=⋅则()()AB AC OB OA OC OA ⋅=-⋅-2OB OC OB OA OA OC OA =⋅-⋅-⋅+ 21OB OC OB OA =⋅-⋅+设OB 与OA 的夹角为α,则OB 与OC 的夹角为2α所以,cos 22cos 1AB AC αα⋅=-+2112(cos )22α=--即,AB AC ⋅的最小值为12-,故选B 。

【举一反三】【相似较难试题】【2015高考天津,理14】在等腰梯形ABCD 中,已知//,2,1,60AB DC AB BC ABC ==∠= ,动点E 和F 分别在线段BC 和DC 上,且,1,,9BE BC DF DC λλ==则AE AF ⋅的最小值为 .【试题分析】本题主要考查向量的几何运算、向量的数量积与基本不等式.运用向量的几何运算求,AE AF ,体现了数形结合的基本思想,再运用向量数量积的定义计算AE AF ⋅,体现了数学定义的运用,再利用基本不等式求最小值,体现了数学知识的综合应用能力.是思维能力与计算能力的综合体现. 【答案】2918【解析】因为1,9DF DC λ=12DC AB =,119199918CF DF DC DC DC DC AB λλλλλ--=-=-==, AE AB BE AB BC λ=+=+,19191818AF AB BC CF AB BC AB AB BC λλλλ-+=++=++=+,()221919191181818AE AF AB BC AB BC AB BC AB BCλλλλλλλλλ+++⎛⎫⎛⎫⋅=+⋅+=+++⋅⋅ ⎪ ⎪⎝⎭⎝⎭19199421cos1201818λλλλ++=⨯++⨯⨯⨯︒2117172992181818λλ=++≥+= 当且仅当2192λλ=即23λ=时AE AF ⋅的最小值为2918. 2.【试卷原题】20. (本小题满分12分)已知抛物线C 的焦点()1,0F ,其准线与x 轴的交点为K ,过点K 的直线l 与C 交于,A B 两点,点A 关于x 轴的对称点为D . (Ⅰ)证明:点F 在直线BD 上; (Ⅱ)设89FA FB →→⋅=,求BDK ∆内切圆M 的方程. 【考查方向】本题主要考查抛物线的标准方程和性质,直线与抛物线的位置关系,圆的标准方程,韦达定理,点到直线距离公式等知识,考查了解析几何设而不求和化归与转化的数学思想方法,是直线与圆锥曲线的综合问题,属于较难题。

【易错点】1.设直线l 的方程为(1)y m x =+,致使解法不严密。

2.不能正确运用韦达定理,设而不求,使得运算繁琐,最后得不到正确答案。

【解题思路】1.设出点的坐标,列出方程。

2.利用韦达定理,设而不求,简化运算过程。

3.根据圆的性质,巧用点到直线的距离公式求解。

【解析】(Ⅰ)由题可知()1,0K -,抛物线的方程为24y x =则可设直线l 的方程为1x my =-,()()()112211,,,,,A x y B x y D x y -,故214x my y x =-⎧⎨=⎩整理得2440y my -+=,故121244y y m y y +=⎧⎨=⎩则直线BD 的方程为()212221y y y y x x x x +-=--即2222144y y y x y y ⎛⎫-=- ⎪-⎝⎭令0y =,得1214y yx ==,所以()1,0F 在直线BD 上.(Ⅱ)由(Ⅰ)可知121244y y m y y +=⎧⎨=⎩,所以()()212121142x x my my m +=-+-=-,()()1211111x x my my =--= 又()111,FA x y →=-,()221,FB x y →=-故()()()21212121211584FA FB x x y y x x x x m →→⋅=--+=-++=-,则28484,93m m -=∴=±,故直线l 的方程为3430x y ++=或3430x y -+=213y y -===±,故直线BD 的方程330x -=或330x -=,又KF 为BKD ∠的平分线,故可设圆心()(),011M t t -<<,(),0M t 到直线l 及BD 的距离分别为3131,54t t +--------------10分 由313154t t +-=得19t =或9t =(舍去).故圆M 的半径为31253t r +== 所以圆M 的方程为221499x y ⎛⎫-+= ⎪⎝⎭【举一反三】【相似较难试题】【2014高考全国,22】 已知抛物线C :y 2=2px(p>0)的焦点为F ,直线y =4与y 轴的交点为P ,与C 的交点为Q ,且|QF|=54|PQ|.(1)求C 的方程;(2)过F 的直线l 与C 相交于A ,B 两点,若AB 的垂直平分线l′与C 相交于M ,N 两点,且A ,M ,B ,N 四点在同一圆上,求l 的方程.【试题分析】本题主要考查求抛物线的标准方程,直线和圆锥曲线的位置关系的应用,韦达定理,弦长公式的应用,解法及所涉及的知识和上题基本相同. 【答案】(1)y 2=4x. (2)x -y -1=0或x +y -1=0. 【解析】(1)设Q(x 0,4),代入y 2=2px ,得x 0=8p,所以|PQ|=8p ,|QF|=p 2+x 0=p 2+8p.由题设得p 2+8p =54×8p ,解得p =-2(舍去)或p =2,所以C 的方程为y 2=4x.(2)依题意知l 与坐标轴不垂直,故可设l 的方程为x =my +1(m≠0). 代入y 2=4x ,得y 2-4my -4=0. 设A(x 1,y 1),B(x 2,y 2), 则y 1+y 2=4m ,y 1y 2=-4.故线段的AB 的中点为D(2m 2+1,2m), |AB|=m 2+1|y 1-y 2|=4(m 2+1).又直线l ′的斜率为-m ,所以l ′的方程为x =-1m y +2m 2+3.将上式代入y 2=4x ,并整理得y 2+4m y -4(2m 2+3)=0.设M(x 3,y 3),N(x 4,y 4),则y 3+y 4=-4m,y 3y 4=-4(2m 2+3).故线段MN 的中点为E ⎝ ⎛⎭⎪⎫2m2+2m 2+3,-2m ,|MN|=1+1m 2|y 3-y 4|=4(m 2+1)2m 2+1m 2.由于线段MN 垂直平分线段AB ,故A ,M ,B ,N 四点在同一圆上等价于|AE|=|BE|=12|MN|,从而14|AB|2+|DE|2=14|MN|2,即 4(m 2+1)2+⎝ ⎛⎭⎪⎫2m +2m 2+⎝ ⎛⎭⎪⎫2m 2+22=4(m 2+1)2(2m 2+1)m 4,化简得m 2-1=0,解得m =1或m =-1, 故所求直线l 的方程为x -y -1=0或x +y -1=0.三、考卷比较本试卷新课标全国卷Ⅰ相比较,基本相似,具体表现在以下方面: 1. 对学生的考查要求上完全一致。

即在考查基础知识的同时,注重考查能力的原则,确立以能力立意命题的指导思想,将知识、能力和素质融为一体,全面检测考生的数学素养,既考查了考生对中学数学的基础知识、基本技能的掌握程度,又考查了对数学思想方法和数学本质的理解水平,符合考试大纲所提倡的“高考应有较高的信度、效度、必要的区分度和适当的难度”的原则. 2. 试题结构形式大体相同,即选择题12个,每题5分,填空题4 个,每题5分,解答题8个(必做题5个),其中第22,23,24题是三选一题。

题型分值完全一样。

选择题、填空题考查了复数、三角函数、简易逻辑、概率、解析几何、向量、框图、二项式定理、线性规划等知识点,大部分属于常规题型,是学生在平时训练中常见的类型.解答题中仍涵盖了数列,三角函数,立体何,解析几何,导数等重点内容。

3. 在考查范围上略有不同,如本试卷第3题,是一个积分题,尽管简单,但全国卷已经不考查了。

四、本考试卷考点分析表(考点/知识点,难易程度、分值、解题方式、易错点、是否区分度题)。

相关文档
最新文档