随笔分类 -  队列技术

摘要:http://queues.io/AboutThere are many queueing systems out there. Each one of them is different and was created for solving certain problems. This page tries to collect the libraries that are widely popular and have a successful record of running on (big) production systems.The goal is to create a qu 阅读全文
posted @ 2013-12-19 22:58 blockcipher 阅读(584) 评论(0) 推荐(0)
摘要:beanstalk中两种重要的数据结构就是集合和最小堆。 1. 集合 集合struct ms { size_t used, cap, last; void **items; ms_event_fn oninsert, onremove;};voidms_init(ms a, ms_event_fn oninsert, ms_event_fn onremove){ a->us... 阅读全文
posted @ 2013-08-24 15:55 blockcipher 阅读(344) 评论(0) 推荐(0)
摘要:1. tube定义 在beanstalk中,tube只是一个消息队列的名字,本身只是作为job的容器,因此不具有复杂的操作。 由于job具有优先级,这里采用最小堆保存job job具有ready和delay两种状态,因此每个tube采用两个最小堆对job进行管理。 tube结构struct tube { uint refs; char name[MAX_TUBE_NAME_LEN]; ... 阅读全文
posted @ 2013-08-24 15:49 blockcipher 阅读(1084) 评论(0) 推荐(0)
摘要:在beanstalk中,网络处理模块没有使用第三方库,而是作者自己实现的一个模块,总计代码不到100行。是epoll的使用典范。1. epoll_eventstruct epoll_event结构如下:struct epoll_event { __uint32_t events; /* Epoll events */ epoll_data_t data; /* User data variable */};typedef union epoll_data { void ptr; int fd; __uint32_t u32; __uint64_t u64; }... 阅读全文
posted @ 2013-08-24 15:07 blockcipher 阅读(370) 评论(0) 推荐(0)
摘要:1. 文件结构组织beanstalk的源码文件物理组织如下:makefile文件:Makefile 数据结构定义: dat.h 主程序: main.c Server实例: serv.c 协议处理: prot.c 连接管理: conn.c tube管理: tube.c job管理: job.c 集合管理: ms.c daemon监听端口: net.c epoll抽象: linux.c 堆操作: heap.c daemon框架: sd-daemon.h sd-daemon.c binlog处理: file.c walg.c 系统时间: tim... 阅读全文
posted @ 2013-08-24 12:32 blockcipher 阅读(567) 评论(0) 推荐(0)
摘要:https://github.com/blog/542-introducing-resqueResqueis our Redis-backed library for creating background jobs, placing those jobs on multiple queues, and processing them later.Background jobs can be any Ruby class or module that responds toperform. Your existing classes can easily be converted to bac 阅读全文
posted @ 2013-08-18 20:36 blockcipher 阅读(224) 评论(0) 推荐(0)
摘要:beanstalk把监听socket加入了epoll,当客户端有连接时,在主循环sockmain中通过处理epoll事件完成对连接的处理。1. 客户端连接处理代码通过前面对主循环的分析可以看出,监听socket的回调处理函数为srvaccept(见如下函数)。通过分析h_accept可以看出,客户端连接的处理包括三个步骤:a.建立连接socket,并将连接设置为非阻塞;b.创建连接管理对象,c.将和客户端的连接加入epoll连接处理#监听服务回调函数,用作接受连接voidsrvaccept(Server *s, int ev){ h_accept(s->sock.fd, ev, s);} 阅读全文
posted @ 2013-02-17 17:23 blockcipher 阅读(377) 评论(0) 推荐(0)
摘要:以后的分析都是基于beanstalk版本1.6版本的源码。1. 服务实例Serverbeanstalk中将一个监听实例抽象成为一个Server, 服务实例是监听指定地址(ip:port)的运行实例。结构如下:serverstruct Server { char *port; //端口 char *addr; //地址 char *user; //用户 Wal wal; //binlog文件 Socket sock; //监听socket连接 Heap conns; //连接堆};2.epoll抽象beanstalk对epoll相关的函数... 阅读全文
posted @ 2013-02-17 16:36 blockcipher 阅读(398) 评论(0) 推荐(0)
摘要:beanstalk是什么?官方网站给出的说明非常简单给力。Beanstalk is a simple, fast work queue.Its interface is generic, but was originally designed for reducing the latency of page views in high-volume web applications by running time-consuming tasks asynchronously.beanstalk是一个简单快速的任务队列,它通过缓存耗时的任务,使其异步执行来减少高容量web应用中页面延迟。更简单的 阅读全文
posted @ 2012-06-03 11:23 blockcipher 阅读(854) 评论(0) 推荐(0)
摘要:本文说明web服务器和应用服务器的区别以及web服务器自身的特点下面引用一篇文章(http://www.netyourlife.net/index.php?action-viewnews-itemid-15557-page-1)来说明。 解析Web服务器和应用服务器的区别通俗的讲,Web服务器传送页面使浏览器可以浏览,然而应用程序服务器提供的是客户端应用程序可以调用(call)的方法(methods)。确切一点,你可以说:Web服务器专门处理HTTP请求(request),但是应用程序服务器是通过很多协议来为应用程序提供(serves)商业逻辑(business logic)。下面让我们来细细 阅读全文
posted @ 2012-06-03 10:14 blockcipher 阅读(254) 评论(0) 推荐(0)