spark与akka_与Akka建立虚拟电厂

spark与akka

For the latest version and dark-mode, read it on my blog.

有关最新版本和暗模式, 请在我的博客上阅读

Around the world, renewable energy use is on the rise, as those alternative energy sources could hold the key to combating climate change.

在全球范围内,可再生能源的使用量正在上升,因为这些替代能源可能成为应对气候变化的关键。

However, with its unpredictable nature, renewable energy generation brings in new technological challenges. Unlike with the old-style centralized fossil fuel generation, in which supply could be turned up and down according to demand, renewable energy generation can’t be forecast precisely. This unpredictable nature of both power generation and power consumption can lead to times of high supply not aligned with times of high demand. To face this problem, Lithium-ion batteries are being used, such as this mega-battery built by Tesla in South Australia. As power consumption is low and generation is high, batteries are able to store the inflating power for later use.

然而,由于其不可预测的性质,可再生能源发电带来了新的技术挑战。 与老式的集中化石燃料发电不同,后者可以根据需求上下调节供应量,而可再生能源发电量则无法精确预测。 发电和功耗的这种不可预测的性质可能导致高供应时间与高需求时间不符。 为了解决这个问题,人们正在使用锂离子电池,例如特斯拉在南澳大利亚生产的这种巨型电池 。 由于功耗低且发电量高,电池能够存储充气功率以备后用。

Tesla’s engineers have expanded this solution by introducing the concept of a Virtual Power Plant. In addition to giant centralized batteries, Tesla can aggregate the power produced by many individual households to form a distributed power grid. As rooftop solar systems coupled with Powerwall residential storage batteries are installed at each house, a cloud-based network is able to keep track on the batteries’ status, charge or discharge them, and to run real-time analysis on data, enabling to optimize power distribution and even manipulating the local power market.

特斯拉的工程师通过引入虚拟电厂的概念扩展了该解决方案。 除了巨型集中式电池外,特斯拉还可以聚合许多家庭所产生的电力,从而形成分布式电网。 由于在每个房屋中都安装了屋顶太阳能系统和Powerwall住宅蓄电池,因此基于云的网络能够跟踪蓄电池的状态,对其进行充电或放电,并对数据进行实时分析,从而优化配电,甚至操纵本地电力市场。

In this post, we will outline the implementation of a simple distributed Virtual Power Plant by using Scala, Akka, and the Actor Model, as we explain the basic ideas behind the Actor Model.

在这篇文章中,当我们解释Actor模型背后的基本思想时,我们将概述使用Scala,Akka和Actor模型实现一个简单的分布式虚拟电厂的实现。

该平台 (The Platform)

We wish to implement a cloud-based service that allows us to connect power-generating units (such as houses) to the network, and to query, at any given moment, the power levels of all houses connected to a given geographical region.

我们希望实现一项基于云的服务,该服务允许我们将发电设备(例如房屋)连接到网络,并在任何给定时刻查询连接到给定地理区域的所有房屋的电力水平。

Image for post

Since a power resource can be a house, but it can also be a physical power plant such as a solar farm or a windmill farm, we use the generalized term Resource to describe any power-generating unit.

由于电力资源可以是房屋,也可以是诸如太阳能场或风车场之类的物理发电厂,因此我们使用通用术语“ Resource来描述任何发电单元。

In the above, a controller sends an HTTP request to connect a specific resource to a specific region in the system. The platform receives a continuous stream of Telemetry data via a dedicated WebSocket, which specifies the current battery level of that resource. The platform supports queries about battery levels of all connected Resources of a given Region.

在上面,控制器发送HTTP请求以将特定资源连接到系统中的特定区域。 该平台通过专用的WebSocket接收连续的遥测数据流,该WebSocket指定该资源的当前电池电量。 该平台支持有关给定地区所有已连接资源的电池电量的查询。

演员模型 (The Actor Model)

The system is expected to receive and process streams of real-time data that are produced by many different power-resources, and which are produced simultaneously. Handling those computations in a single thread of execution would result in unusably slow applications, memory problems, crashes, and timeouts. To support such the concurrent nature of such a platform, there is a need for Multithreading.

预计该系统将接收和处理由许多不同电源产生并同时产生的实时数据流。 在单个执行线程中处理这些计算将导致应用程序缓慢,内存问题,崩溃和超时。 为了支持这种平台的这种并发特性,需要Multithreading

锁很难 (Locking is hard)

With Multithreading, it is hard to guarantee a true encapsulation of shared resources. As threads can be interleaved in an arbitrary and non-deterministic way, it is easy to introduce rase-conditions and to reach a corrupted state. The only way to eliminate those risks is by coordinating those threads, usually with Locking.

使用多线程,很难保证共享资源的真正封装。 由于可以以任意和不确定的方式交错线程,因此很容易引入擦除条件并达到损坏状态 。 消除这些风险的唯一方法是协调这些线程,通常是使用Locking

While Locking ensures the validity of the execution, it comes with a heavy price: Locks dramatically limit parallelism, as threads often cannot work in parallel. Furthermore, it is easy to introduce deadlocks and livelocks, as coordinating between a pool of threads is complex in nature. Another considerable complexity with Locks is with Horizontal scalability — When it comes to coordinating across multiple machines, locks are also being distributed. Unfortunately, distributed locks are several magnitudes less efficient than local locks and usually impose a hard limit on scaling out. Distributed lock protocols require several communication round-trips over the network across multiple machines, which dramatically increases latency.

虽然Locking确保执行的有效性,但代价不菲:Locks极大地限制了

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值