Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between Python parallelism and concurrency

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what is the difference between Python parallelism and concurrency". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the difference between Python parallelism and concurrency".

The difference between parallelism and concurrency-parallel

If you do something at the same time, you can do several things at the same time without interfering with each other.

Parallel: the concept of multiple lanes on a highway, each of which may have vehicles running at the same time.

Concurrent-concurrency

Do some things at the same time, but there are things to deal with in a period of time

Concurrency: it is the time when many vehicles have to pass through the road within a time, such as a large wave of people flocking to the canteen at the end of the day, and a large wave of requests to the server when they rush to buy.

How to deal with concurrency?

1. Queue, buffer

When waiting for food, the queue is first-in, first-out. This queue is the buffer zone, and a priority queue can be set up if ladies have priority.

Classes of queue module, Queue, LifoQueue, PriorityQueue

2. Scramble for

When playing food, whoever grabs the playing window will hit first, here is a locking mechanism, scrambling is also a high concurrency solution, but it is not good, some people may not be able to get it for a long time.

3. Pretreatment

The popular dishes will be prepared in advance, and the unpopular dishes will be cooked temporarily, which is a common way to load the data needed by users in advance, pre-processing ideas and caching.

4. Parallel

When too many people eat, they can open multiple windows and form multiple queues for parallel cooking, resulting in rising costs, just like buying more servers, or opening more processes and threads to achieve parallel processing and solving concurrency. This is the idea of horizontal expansion.

Note:

If the thread runs on a single CPU, it will not be processed in parallel.

However, most servers are multi-CPU, and the deployment of services is often multi-machine and distributed, which is processed in parallel.

5. Speed up

When it comes to the speed of a single window, that is, to improve the performance of a single CPU, or to install more CPU on a single server, this is a vertical expansion idea.

6. Message middleware

Build a nine-zigzag ileal corridor outside the canteen.

What is mentioned in the first point is the establishment of queues within the program, where the message queue is outside the program.

Common message middleware includes RabbitMQ, ActiveMQ (Apache), RocketMQ (Ali Apache) and Kafka.

Thank you for your reading, the above is the content of "what is the difference between Python parallelism and concurrency". After the study of this article, I believe you have a deeper understanding of what is the difference between Python parallelism and concurrency. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report