当前位置:网站首页>Lite actor: lightweight optimization of ark actor concurrency model
Lite actor: lightweight optimization of ark actor concurrency model
2022-07-26 07:11:00 【51CTO】
Lite Actor: Ark Actor Lightweight optimization of concurrency model
Concurrency model is a programming model used to realize concurrent tasks in different application scenarios , By using multithreading reasonably , It can reduce the cost of application development and maintenance , At the same time, it can better improve the performance of applications in multi-core devices . With IoT In this era, the application scenarios are becoming more and more complex 、 The increasing number of multi-core devices , The concurrency model is very important , In this issue, we will bring you the ark compiler to the tradition Actor Lightweight optimization of concurrency model .
One 、 What is the concurrency model ?
In the operating system , Concurrency is the ability of tasks to execute out of order or in partial order without affecting the final execution result , Pictured 1 Shown , In a period of time, there may be multiple tasks between the start and completion of running , meanwhile , Concurrent units can also be executed in parallel under multi-core devices , It can greatly improve the performance of multi-core equipment .

chart 1 Parallel execution of concurrent units
In daily development , Due to the variety of concurrent tasks , Tasks may be split in different ways , The way of communication between threads may also be different , Therefore, multithreaded concurrent tasks in different scenarios can be implemented through different concurrent programming models . Common concurrency models are divided into memory sharing concurrency model and message communication concurrency model . among , The concurrency model based on memory sharing has data competition , Locks or other synchronization mechanisms are often needed to protect shared variable data . The concurrency model based on message communication , There is no need for developers to face a series of complex and accidental problems caused by locks , At the same time, the concurrency is relatively high .
As a typical representative of message based communication concurrency model ,Actor The concurrency model is very popular among developers . below , We will bring you Actor Analysis of concurrency model .
Two 、Actor Concurrency model
Actor It is a distributed concurrency model with a long history , Based on events ( news ) Mechanism to transfer data , It can effectively avoid resource contention in threads 、 Deadlock, etc . In this section, we will introduce Actor The interaction principle of concurrency model and in JS Application in .
1. Interaction principle
Pictured 2 Shown , In a typical Actor In the interactive process , each Actor Concurrent processing of main thread tasks , Every Actor There is a message queue and a single thread execution module inside , The message queue is responsible for receiving the main thread and others Actor Request , The single thread execution module is responsible for processing requests serially 、 To the other Actor Send requests and create new Actor. because Actor It's asynchronous , each Actor There is no data competition between them , therefore Actor Can run with high concurrency .

chart 2 Actor Interaction process
2. Application scenarios
Actor Concurrency model is widely used in Erlang、Haskell、Akka(Java)、JS Programming language , Next we will introduce Actor The concurrency model is JS Application in .
(1) Worker Introduce
as everyone knows ,JS Since its birth, it has been single threaded , To solve the problem caused by single thread I/O Blocking problem ,JS Through asynchronous callback and event mechanism , It fully improves the response speed of lightweight events under single thread . But if you encounter some complex tasks , such as CPU Intensive computing tasks 、I/O Intensive task 、 Synchronization tasks, etc , Still using single thread execution is a little weak , Unable to solve the thread blocking problem of complex tasks . therefore ,JS Need to introduce multi-threaded task support .
Worker Is a typical JS Multithreading solution , be based on Actor Concurrent model implementation , by JS Create a multithreaded concurrent environment . Pictured 3 Shown , stay Worker In the interactive process of ,JS The main thread can create multiple Worker Sub thread , each Worker Threads are isolated from each other , And pass the object through serialization , wait until Worker The thread completes the calculation task , Then return the result to the main thread .

chart 3 Worker Interaction process
(2) Worker defects
Worker It implements complex JS Multithreading concurrent execution of applications , To a certain extent, it increases the complexity JS Operational efficiency of applications . however , Because each Worker Threads have independent virtual machine instances , And no data is shared between instances , bring JS Worker Slow startup speed 、 High memory usage .
3、 ... and 、Lite Actor
In order to make JS Applications can make full use of the computing power of multi-core devices to better improve performance , Ark compiler proposed Lite Actor Concept , And aim at Worker The defects are optimized .
1. Principle introduction
Ark compiler JS Runtime in traditional Actor Based on the concurrency model , By sharing Actor Immutable objects in instances , To reduce each Actor The data carried by the instance , Improved every Actor Operation performance of , So as to achieve Actor Lightweight optimization of concurrency model .

chart 4 Lite Actor
2. Worker Optimize
Ark compiler JS The runtime is based on Lite Actor Concept pair Worker optimized , The specific optimization is as follows :
● Ark compiler JS Run time through the built-in bytecode file manager , We have finished checking multiple Worker Sharing of cached bytecode files between , It greatly reduces the pre loading processing time and memory occupation of bytecode .
● Ark compiler JS Runtime combination TS Type analysis system and object separation technology , It's done Worker Middle part TS Identification and sharing of type information and quasi-static type information , To a certain extent, reduce Worker Memory usage of threads and Worker The transmission of information between threads takes time . meanwhile , Because the shared part does not need to be serialized and copied , therefore Worker The serialization duration of has also been optimized . at present , There is still much room for improvement in the remaining unshared data , This part of the work will continue , Let's look forward to it together .
● Data for external memory , For example, string in bytecode , Because it is not affected JS memory management , Sharing can also be realized in the future .

chart 5 Worker Optimize
3. Performance comparison
Using the ark compiler Lite Actor After optimization ,Worker The performance of has been significantly increased , Pictured 6 Shown , It's not hard to see. , Compared with tradition Actor Concurrency model ,Worker The startup time and memory usage of are optimized 50% above .

chart 6 Performance and memory comparison
That's what this issue is all about , Ark compiler JS Run time through traditional Actor Lightweight optimization of concurrency model , Greatly improved Worker Start up performance . At present Lite Actor There is still much room for exploration , We look forward to the majority of developers to join us , Witness the infinite possibility of interconnection of all things .
边栏推荐
- npm 命令
- Business secret series -- Talking about the evaluation of commercial passwords from the perspective of Party A and Party B (I)
- 为什么extern使用const修饰的变量会编译不过?
- Kernel pwn 入门 (5)
- [hard ten treasures] - 7.2 [dynamic RAM] analysis of the difference between DDR4 and DDR3
- Linux c SQLite database usage
- Analysis of strong tennis cup 2021 PWN competition -- baby_ diary
- 在第一次使用德国小鸡要注意的地方
- Deep learning visualization
- Do you want to restart the database to replace the license?
猜你喜欢

A guide for you to fully use TS

Basic operations and common functions of MySQL table creation

Rectification ideas for the previous article

Opencv learn read images videos and webcams
![[749. Isolate virus]](/img/12/b8c3cdb664f4415d20c2fc5c697a41.png)
[749. Isolate virus]

Kernel pwn 入门 (5)
![[hardware ten treasures] - 7.1 [dynamic RAM] key points of DDR hardware design](/img/ba/87cd3b1600bcb6f2839e7bb093ff62.png)
[hardware ten treasures] - 7.1 [dynamic RAM] key points of DDR hardware design

Opencv learning drawing shapes and text

Drools(2):Drools快速入门

How to use Hyper-V in win10 Home Edition
随机推荐
Opencv learning basic functions
Realization of LED water lamp based on C51
火焰图分析Flink反压
20220725 自动控制原理中的卷积Convolution
20220725 convolution in automatic control principle
Celery takes up large memory - memory leak
opengauss简易版安装报错
“蔚来杯“2022牛客暑期多校训练营1补题记录(ACDGIJ)
LTS(Light-Task-Scheduler)
Question: can't download sh shellcheck Please install it manually and some commands of shell script
A guide for you to fully use TS
Advanced Mathematics (Seventh Edition) Tongji University General exercises two person solution
MySQL intent lock
微信小程序 - 从入门到入土
"XXXX" is running, which may cause the system to jam, reduce the standby time, and click Close "
buuReserve(4)
10 papers of ant security laboratory were included by ccf-a top meeting to explore the realization of AI credibility from the perspective of algorithm
Business secret series -- Talking about the evaluation of commercial passwords from the perspective of Party A and Party B (I)
QT listens for socket events and uses qsocketnotifier class
MySQL isolation level transactions