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 are the characteristics of Beanstalkd

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the relevant knowledge of "what are the characteristics of Beanstalkd". In the operation of practical cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Design thought

High performance is inseparable from asynchronism, asynchrony can not be separated from queues, and its interior is the principle of Producer-Comsumer mode.

Figure 1 Producer-Comsumer mode

Application

Beanstalkd, a high-performance, lightweight distributed memory queue system, was originally designed to reduce the page access latency of high-capacity Web applications by asynchronously executing time-consuming tasks in the background. Facebook Causes applications with 9.5 million users have been supported. Later, it was open source, and now PostRank is deployed and used on a large scale to handle * tasks on a daily basis. Beanstalkd is a typical Memcached-like design with the same protocol and usage style, so users who have used memcached will feel Beanstalkd deja vu.

Core concept

Core concepts in Beanstalkd design:

◆ job

A task that needs to be processed asynchronously is the basic unit in Beanstalkd and needs to be placed in a tube.

◆ tube

A well-known task queue, which stores a uniform type of job, is the object of producer and consumer operations.

◆ producer

The producer of Job, using the put command to put a job into a tube.

◆ consumer

The consumer of Job uses the reserve/release/bury/delete command to get the job or change the state of the job.

The life cycle of a job in Beanstalkd is shown in figure 2. A job has four states: READY, RESERVED, DELAYED, and BURIED. When producer directly put a job, the job is in the READY state, waiting for the consumer to process. If you choose to delay the put,job, you will first go to the DELAYED state, and then migrate to the READY state after the waiting time. After consumer acquires the job of the current READY, the state of the job is migrated to RESERVED, so that other consumer can no longer manipulate the job. When the consumer completes the job, you can choose the delete, release or bury operation; after delete, the job dies from the system and cannot be obtained again; the release operation can re-migrate the job state back to READY (or delay the state transition operation), so that other consumer can continue to obtain and execute the job What's interesting is the bury operation. You can hibernate the job, and then return the dormant job kick to READY state when needed, or job in delete BURIED state. It is precisely with these interesting operations and states that many meaningful applications can be made based on this. For example, to implement a circular queue, you can hibernate the job in the RESERVED state, and then kick the job in the BURIED state back to the READY state when there is no job in the BURIED state.

Figure 2 Life cycle of job in Beanstalkd

Characteristics

The source code on which Beanstalkd is based is easy to install and use, and is skipped here. Here we focus on some of its very nice features.

◆ priority

Priority ranges from 0 to 2 are supported. The lower the value, the higher the priority. The default priority is 1024.

◆ persistence

Job and its status can be recorded in a file through binlog, and the previous job and state can be restored by reading binlog the next time Beanstalkd starts.

◆ distributed fault tolerance

Distributed design is similar to Memcached, beanstalkd server do not know the existence of each other, are distributed through client and go to a specific server to get job according to the tube name.

◆ timeout control

In order to prevent a consumer from occupying the task for a long time but cannot handle it, Beanstalkd sets the timeout time for the reserve operation. If the consumer cannot be completed within the specified time, the job,job will be migrated back to the READY state for other consumer to execute.

Deficiency

In use, it is found that a Beanstalkd does not provide an operation to delete a tube, so we can only delete the job of the tube in turn, and let the Beanstalkd automatically delete the empty tube. In addition, Beanstalkd does not support client-side authentication mechanism (developers locate the application scenario in the local area network).

This is the end of the content of "what are the characteristics of Beanstalkd"? thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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

Development

Wechat

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

12
Report