自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

如何安裝和使用Beanstalkd工作隊列

網(wǎng)絡 通信技術 網(wǎng)絡管理 網(wǎng)絡運維
Beanstalkd首先是解決了一個流行的web應用程序的需求。Beanstalkd旨在成為一個工作隊列,為了實現(xiàn)這一目的,它作為一種輕量級的、快速有效的應用程序基于C編程語言。精益建筑還允許它是安裝和使用非常簡單,使它適合大多數(shù)用例。

介紹

小心翼翼地宣布每一元素的職責部署應用程序棧帶來很多好處,包括簡單的診斷問題時發(fā)生,規(guī)模迅速的能力,以及更清晰的管理范圍涉及的組件。

在當今世界web服務的工程,一個關鍵的組件實現(xiàn)上述場景涉及利用消息隊列和工作(或任務)。這些通常是彈性和靈活的應用程序很容易實現(xiàn)和設置。他們是完美的分裂的不同部分之間的業(yè)務邏輯應用程序包時生產(chǎn)。

在這篇文章中,我們的應用程序級別系列通信解決方案,我們將看看Beanstalkd創(chuàng)建這個片段的分離。

什么是Beanstalkd

Beanstalkd首先是解決了一個流行的web應用程序的需求(Facebook上的原因)。目前,這是一個絕對可靠,易于安裝的消息傳遞服務,是完美的開始和使用。

如前所述,Beanstalkd的主要用例是管理不同部分和工人之間的工作流應用程序的部署通過工作隊列和消息堆棧,類似于其他受歡迎的解決方案,比如RabbitMQ。然而,創(chuàng)建Beanstalkd使它有別于其他工作。

自成立以來,與其他解決方案,Beanstalkd旨在成為一個工作隊列,而不是一把雨傘工具來滿足許多需求。為了實現(xiàn)這一目的,它作為一種輕量級的、快速有效的應用程序基于C編程語言。精益建筑還允許它是安裝和使用非常簡單,使它適合大多數(shù)用例。

Features(特性)

能夠監(jiān)控工作返回ID,在創(chuàng)建返回,只有一個的特性使它有別于其他的Beanstalkd。提供一些其他有趣的功能是:

1.持久性—>Beanstalkd運行使用內(nèi)存,但也提供了持久性支持。

2.優(yōu)先級—>與大多數(shù)選擇一樣,Beanstalkd提供了不同的任務的優(yōu)先級來處理緊急事情時需要。

3.分布 —->不同的服務器實例可以分布類似于Memcached是如何工作的。

4.掩蓋 —-> 有可能通過掩蓋它無限期延期的作業(yè)(即任務)。

5.第三方工具—>Beanstalkd附帶各種第三方工具包括綜合領先指標和基于web的管理控制臺。

6.過期 —->工作可以設置為過期,auto-queue之后(TTR – Time To Run).

Beanstalkd使用案例

一些模范的Banstalkd用例:

允許web服務器快速響應請求,而不是被迫當場曾推高程序執(zhí)行

在指定的時間間隔執(zhí)行某些工作(即爬行web)

分發(fā)到多個工作人員進行處理

讓離線客戶端(例如一個斷開連接的用戶)獲取數(shù)據(jù)在稍后的時間,而不是讓它永久失去了通過一個工人

引入完全異步功能的后端系統(tǒng)

訂購和優(yōu)先任務

應用程序負載不同員工之間保持平衡

極大地提高應用程序的可靠性和正常運行時間

處理CPU密集型工作(視頻、圖片等)

發(fā)送電子郵件到您的列表和更多。

Beanstalkd元素

就像大多數(shù)應用程序,Beanstalkd附帶自己的術語來解釋它的部分。

Tubes / Queues

Beanstalkd管翻譯從其他消息傳遞應用程序隊列。他們是通過工作(或消息)轉(zhuǎn)移到消費者(即工人)。

Jobs / Messages

由于Beanstalkd是一個工作隊列,通過管稱為轉(zhuǎn)移工作是什么——類似于所發(fā)送的消息。

Producers / Senders

生產(chǎn)商,類似于高級消息隊列協(xié)議的定義,是應用程序創(chuàng)建和發(fā)送工作(或消息)。他們正在使用的消費者。

Consumers / Receivers

接收器是不同的應用程序的堆棧從管找份工作,由生產(chǎn)者進行處理。

在Ubuntu 13安裝Beanstalkd

可以很簡單獲得Beanstalkd通過包管理器才能和開始。然而,在幾個命令,您還可以從源下載并安裝它。

注意:我們將執(zhí)行安裝和執(zhí)行行動列在這里的新鮮和新創(chuàng)建的液滴由于各種原因。如果你是積極服務客戶,可能會修改您的系統(tǒng),不要打破任何工作和不運行在問題,強烈建議您試著在一個新系統(tǒng)下面的說明。

使用aptitude安裝:

下載并安裝Beanstalkd運行以下命令:

  1. aptitude install -y beanstalkd 

編輯默認配置文件讓隨著系統(tǒng)啟動

  1. vim /etc/default/beanstalkd 

打開文件后,向下滾動并找到底部線#開始= yes。將其更改為:

  1. START=yes 

下面介紹源碼安裝

我們需要從源代碼安裝過程的一個關鍵工具- Git。

運行以下獲取Git在你系統(tǒng)上:

  1. aptitude install -y git 

下載必要的開發(fā)工具軟件包:

  1. aptitude install -y build-essential 

使用Git克隆(下載)官方庫:

  1. git clone https://github.com/kr/beanstalkd 

進入到下載目錄:

  1. cd beanstalkd 

從源代碼構(gòu)建應用程序:

  1. make 

安裝:

  1. make install 

再介紹一下centos下源碼安裝:

  1. 下載地址: 
  2.   
  3. wget   http://cloud.github.com/downloads/kr/beanstalkd/beanstalkd-1.4.6.tar.gz 
  4.   
  5. 解壓: 
  6.   
  7. tar xzf beanstalkd-1.4.6.tar.gz 
  8.   
  9. cd beanstalkd-1.4.6 
  10.   
  11. /configure 
  12.  
  13. make 
  14.   
  15. make install 
  16.   
  17. 默認安裝路徑 :/usr/local/bin/ 
  18.   
  19. 查看版本: 
  20.   
  21. /usr/local/bin/beanstalkd -v 
  22.   
  23. 1.4.6 

#p#

再附加一個啟動腳本,從Fedora下挖來的 startup 腳本:

  1. #!/bin/sh 
  2. # beanstalkd - a simple, fast workqueue service 
  3. # chkconfig:   - 57 47 
  4. # description: a simple, fast workqueue service 
  5. # processname:  beanstalkd 
  6. # config:       /etc/sysconfig/beanstalkd 
  7. #              
  8.   
  9. ### BEGIN INIT INFO 
  10. # Provides: beanstalkd 
  11. # Required-Start: $local_fs $network $remote_fs 
  12. # Required-Stop: $local_fs $network $remote_fs 
  13. # Default-Stop: 0 1 2 6 
  14. # Short-Description: start and stop beanstalkd 
  15. # Description: a simple, fast work-queue service 
  16. ### END INIT INFO 
  17.   
  18. # Source function library. 
  19. /etc/rc.d/init.d/functions 
  20.   
  21. # Source networking configuration. 
  22. /etc/sysconfig/network 
  23.   
  24. # Check that networking is up. 
  25. [ "$NETWORKING" = "no" ] && exit 
  26. exec="/usr/local/bin/beanstalkd" 
  27. prog=$(basename $exec) 
  28.  
  29. # default options, overruled by items in sysconfig 
  30. BEANSTALKD_ADDR=127.0.0.1 
  31. BEANSTALKD_PORT=11300 
  32. BEANSTALKD_USER=beanstalkd 
  33.   
  34. [ -e /etc/sysconfig/beanstalkd ] && . /etc/sysconfig/beanstalkd 
  35.   
  36. lockfile=/var/lock/subsys/beanstalkd 
  37.  
  38. start() { 
  39. [ -x $exec ] || exit 5 
  40. echo -n $"Starting $prog: " 
  41. # if not running, start it up here, usually something like "daemon $exec" 
  42. options="-l ${BEANSTALKD_ADDR} -p ${BEANSTALKD_PORT} -u ${BEANSTALKD_USER}" 
  43. if [ "${BEANSTALKD_MAX_JOB_SIZE}" != ""  ]; then 
  44. options="${options} -z ${BEANSTALKD_MAX_JOB_SIZE}" 
  45. fi 
  46.  
  47. if [ "${BEANSTALKD_BINLOG_DIR}" != "" ]; then 
  48. if [ ! -d "${BEANSTALKD_BINLOG_DIR}" ]; then 
  49. echo "Creating binlog directory (${BEANSTALKD_BINLOG_DIR})" 
  50. mkdir -p ${BEANSTALKD_BINLOG_DIR} && chown ${BEANSTALKD_USER}:${BEANSTALKD_USER} ${BEANSTALKD_BINLOG_DIR} 
  51. fi 
  52. options="${options} -b ${BEANSTALKD_BINLOG_DIR}" 
  53. if [ "${BEANSTALKD_BINLOG_FSYNC_PERIOD}" != "" ]; then 
  54. options="${options} -f ${BEANSTALKD_BINLOG_FSYNC_PERIOD}" 
  55. else 
  56. options="${options} -F" 
  57. fi 
  58. if [ "${BEANSTALKD_BINLOG_SIZE}" != "" ]; then 
  59. options="${options} -s ${BEANSTALKD_BINLOG_SIZE}" 
  60. fi 
  61. fi 
  62.  
  63. daemon $exec -d $options 
  64. retval=$? 
  65. echo 
  66. [ $retval -eq 0 ] && touch $lockfile 
  67. return $retval 
  68.   
  69. stop() { 
  70. echo -n $"Stopping $prog: " 
  71. # stop it here, often "killproc $prog" 
  72. killproc $prog -INT 
  73. retval=$? 
  74. echo 
  75. [ $retval -eq 0 ] && rm -f $lockfile 
  76. return $retval 
  77.   
  78. restart() { 
  79. stop 
  80. start 
  81.   
  82. reload() { 
  83. restart 
  84.   
  85. force_reload() { 
  86. restart 
  87.   
  88. rh_status() { 
  89. # run checks to determine if the service is running or use generic status 
  90. status $prog 
  91.   
  92. rh_status_q() { 
  93. rh_status >/dev/null 2>&1 
  94.  
  95.  
  96. case "$1" in 
  97. start) 
  98. rh_status_q && exit 0 
  99. $1 
  100. ;; 
  101. stop) 
  102. rh_status_q || exit 0 
  103. $1 
  104. ;; 
  105. restart) 
  106.  $1 
  107. ;; 
  108. reload) 
  109. rh_status_q || exit 7 
  110. $1 
  111. ;; 
  112. force-reload) 
  113. force_reload 
  114. ;; 
  115. status) 
  116. rh_status 
  117. ;; 
  118. condrestart|try-restart) 
  119. rh_status_q || exit 0 
  120. restart 
  121. ;; 
  122. *) 
  123. echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" 
  124. exit 2 
  125. esac 
  126. exit $? 

#p#

使用Beanstalkd

在安裝之后,您就可以開始使用Beanstalkd服務器。以下是運行守護進程的選項:

  1. -b DIR   wal directory 
  2. -f MS    fsync at most once every MS milliseconds (use -f0 for "always fsync") 
  3. -F       never fsync (default) 
  4. -l ADDR  listen on address (default is 0.0.0.0) 
  5. -p PORT  listen on port (default is 11300) 
  6. -u USER  become user and group 
  7. -z BYTES set the maximum job size in bytes (default is 65535) 
  8. -s BYTES set the size of each wal file (default is 10485760) 
  9. (will be rounded up to a multiple of 512 bytes) 
  10. -c       compact the binlog (default) 
  11. -n       do not compact the binlog 
  12. -v       show version information 
  13. -V       increase verbosity 
  14. -h       show this help 

使用例子:

  1. # Usage: beanstalkd -l [ip address] -p [port #] 
  2. # For local only access: 
  3. beanstalkd -l 127.0.0.1 -p 11301 & 

管理服務:

如果安裝包管理器(i.e. aptitude),你將能夠管理Beanstalkd作為服務守護進程。

  1. # To start the service: 
  2. service beanstalkd start 
  3.   
  4. # To stop the service: 
  5. service beanstalkd stop 
  6.   
  7. # To restart the service: 
  8. service beanstalkd restart 
  9.   
  10. # To check the status: 
  11. service beanstalkd status 

獲得Beanstalkd客戶端庫

Beanstalkd配有一長串的支持客戶端庫來處理許多不同的應用程序部署。這個列表的支持語言和框架,包括:

●Python

●Django

●Go

●Java

●Node.js

●Perl

●PHP

●Ruby

●and more.

查看完整列表支持,尋找你最喜歡的語言和安裝說明,查看客戶端庫頁面Beanstalkd Github上。

使用Beanstalkd

在本節(jié)之前,完成這篇文章,讓我們快速Beanstalkd的基本用法。在我們的示例中,我們將使用Python語言和Beanstald Python bindings ——beanstalkc。

安裝beanstalkc,運行以下命令:

  1. pip install pyyaml 
  2. pip install beanstalkc 

基本操作

在所有Python文件你想處理Beanstalkd時,需要導入beanstalkc并連接:

  1. import beanstalkc 
  2.   
  3. # Connection 
  4. beanstalk = beanstalkc.Connection(host='localhost'port=11301

 

To enqueue a job:

  1. beanstalk.put('job_one') 

To receive a job:

  1. job = beanstalk.reserve() 
  2. job.body == 'job_one' 

To delete a job after processing it:

  1. job.delete() 

To use a specific tube (i.e. queue / list):

  1. beanstalk.use('tube_a') 

To list all available tubes:

  1. beanstalk.tubes() 
  2. # ['default', 'tube_a'] 

Final example (nano btc_ex.py):

  1. import beanstalkc 
  2.   
  3. # Connect 
  4. beanstalk = beanstalkc.Connection(host='localhost'port=11301
  5.   
  6. # See all tubes: 
  7. beanstalk.tubes() 
  8.  
  9. # Switch to the default (tube): 
  10. beanstalk.use('default') 
  11.   
  12. # To enqueue a job: 
  13. beanstalk.put('job_one') 
  14.   
  15. # To receive a job: 
  16. job = beanstalk.reserve() 
  17.  
  18. # Work with the job: 
  19. print job.body 
  20.   
  21. # Delete the job:  
  22. job.delete() 

當您運行上面的腳本時,您應該會看到工作的主體被打印:

  1. python btc_ex.py 
  2. # job_one 

 

 

看到更多關于beanstalkd(beanstalkc)操作,查看它的入門教程–>http://beanstalkc.readthedocs.org/en/latest/tutorial.html

責任編輯:守望幸福 來源: 51CTO.com
相關推薦

2022-01-12 12:35:36

Linuxworkqueue工作隊列

2011-06-20 06:14:15

ibmdwLinux

2021-12-27 07:55:59

Linux 中斷處理Linux 系統(tǒng)

2011-09-14 10:08:07

Beanstalkd

2023-04-02 21:45:46

Vim文本編輯器

2022-03-09 13:53:54

??繀^(qū)Latte DocUbuntu

2011-09-05 13:41:32

UbuntueCryptfs

2023-04-24 08:00:00

2011-09-15 16:44:36

UbuntuGoldenDict

2024-03-22 12:10:39

Redis消息隊列數(shù)據(jù)庫

2010-03-29 16:00:19

Nginx 虛擬機

2023-03-14 16:44:20

Linuxhtop

2023-06-12 17:54:50

2023-07-05 16:45:30

WiresharkLinux

2019-09-11 14:30:45

UbuntuLinuxR語言

2024-04-30 08:09:10

PulsarArthas消息隊列

2020-09-30 11:33:42

云計算

2018-02-25 11:03:00

LinuxUbuntuEncryptpad

2022-09-19 08:45:52

Telnet系統(tǒng)Linux

2020-07-16 15:01:46

物聯(lián)網(wǎng)數(shù)字工作遠程工作
點贊
收藏

51CTO技術棧公眾號