[文章作者:张宴 本文版本:v1.0 最后修改:2011.07.26 转载请注明原文链接:http://blog.zyan.cc/httpsqs_1_7/]

  HTTPSQS(HTTP Simple Queue Service)是一款基于 HTTP GET/POST 协议的轻量级开源简单消息队列服务,使用 Tokyo Cabinet 的 B+Tree Key/Value 数据库来做数据的持久化存储。

  项目网址http://code.google.com/p/httpsqs/
  使用文档http://blog.zyan.cc/httpsqs/
  使用环境:Linux(同时支持32位、64位操作系统,推荐使用64位操作系统)
  软件作者:张宴



  HTTPSQS 1.7 版本更新内容:

  下面的内容不只是介绍 HTTPSQS 1.7 更新了哪些东西,更多的介绍在于:如何绕开 Libevent 2.0.x evhttp 使用过程中,无法正常处理包含“|”字符的 URI 参数的问题;提供了一份比 Libevent 官方网站更新的在线文档;Linux 下如何动态编译程序,运行时不用在 /etc/ld.so.conf 文件中添加动态链接库路径。

  1、针对 Libevent 2.0.x 版本 evhttp_parse_query 函数的 BUG。

  网友发邮件,反应了一个 HTTPSQS 的 BUG,见下图,data 的值为NULL。我查找发现,这不是 HTTPSQS 的 BUG,而是 Libevent 2.0.x 版本的 BUG。在 Libevent 1.4.14b 版本中,evhttp_parse_query 函数是能够正常处理包含“|”字符的 URI 的,而在 Libevent 2.0.12 版本中,同样使用 evhttp_parse_query 函数,包含“|”字符的 URI  处理后的结果是 NULL。

  点击在新窗口中浏览此图片

  对比 Libevent 2.0.12 和 1.4.14b 版本的 evhttp_parse_query 函数代码,发现在 2.0.12 版本中,evhttp_parse_query(const char *uri, struct evkeyvalq *headers) 实际变成了调用 evhttp_parse_query_impl(uri, headers, 1) 函数,该函数内再调用的一个 2.0.x 版本新增的函数 evhttp_uri_parse(const char *source_uri),逻辑处理代码在 evhttp_uri_parse_with_flags(const char *source_uri, unsigned flags) 函数中。evhttp_uri_parse(const char *source_uri) 无法正确解析含有“|”的URL,遇到类似“http://127.0.0.1:1218/?opt=get&name=aaa|bbb”的URL,直接返回NULL,也就是 BUG 所在。

  libevent-2.0.12-stable/http.c
  点击在新窗口中浏览此图片

  点击在新窗口中浏览此图片

  点击在新窗口中浏览此图片

  不建议修改第三方库,这个 BUG 还是留给 Libevent 自己去解决吧。使用 Libevent 2.0.x evhttp 作开发的同学,遇到URI参数中包含“|”的问题,注意一下吧。

  我修改了 HTTPSQS 代码,在 HTTPSQS 1.7 版本,采用以下方式来绕开evhttp_uri_parse(const char *source_uri)函数,解决这个问题。其中用到了 Libevent 2.0.x  evhttp_request 结构体中新增的 struct evhttp_uri *uri_elems,以及新增的函数 evhttp_parse_query_str (const char *uri, struct evkeyvalq *headers)。

  Libevent 的官方文档只有 1.4.10-stable2.0.1-alpha 版本的,2.0.1x 很多新增的函数、结构体都没有。

  我这里提供一份最新的 Libevent 在线文档: http://blog.zyan.cc/book/libevent/



  2、静态编译改为动态编译,并指定程序运行时查找的动态链接库路径

  一些网友反映,CentOS 6.0、Fedora 等系统没有默认安装lz、lbz2、lrt、...等静态链接库,出现无法编译HTTPSQS的情况:
gcc -o httpsqs httpsqs.c prename.c -L/usr/local/libevent-2.0.10-stable/lib/ -levent -L/usr/local/tokyocabinet-1.4.47/lib/ -ltokyocabinet -I/usr/local/libevent-2.0.10-stable/include/ -I/usr/local/tokyocabinet-1.4.47/include/ -lz -lbz2 -lrt -lpthread -lm -lc -O2 -g --static  
/usr/bin/ld: cannot find -lz  
/usr/bin/ld: cannot find -lbz2  
/usr/bin/ld: cannot find -lrt  
/usr/bin/ld: cannot find -lpthread  
/usr/bin/ld: cannot find -lm  
/usr/bin/ld: cannot find -lc  
/usr/bin/ld: cannot find -lc  
collect2: ld 返回 1  
make: *** [httpsqs] 错误 1


  HTTPSQS 1.7 版本改为动态编译,编译时使用“-Wl,-rpath”参数指定了程序运行时的动态库搜索路径。这样就不需要在 /etc/ld.so.conf 中 添加 HTTPSQS 程序运行时需要的 libevent、tokyocabinet 动态链接库路径了,可以避免与其他软件(例如:Memcached、TT)使用的 libevent、tokyocabinet 动态链接库版本相冲突。详情请见 Makefile 文件:
# Makefile for httpsqs
CC=gcc
CFLAGS=-Wl,-rpath,/usr/local/libevent-2.0.12-stable/lib/:/usr/local/tokyocabinet-1.4.47/lib/ -L/usr/local/libevent-2.0.12-stable/lib/ -levent -L/usr/local/tokyocabinet-1.4.47/lib/ -ltokyocabinet -I/usr/local/libevent-2.0.12-stable/include/ -I/usr/local/tokyocabinet-1.4.47/include/ -lz -lbz2 -lrt -lpthread -lm -lc -O2 -g

httpsqs: httpsqs.c
  $(CC) -o httpsqs httpsqs.c prename.c $(CFLAGS)
  @echo ""
  @echo "httpsqs build complete."
  @echo ""  

clean: httpsqs
  rm -f httpsqs

install: httpsqs
  install $(INSTALL_FLAGS) -m 4755 -o root httpsqs $(DESTDIR)/usr/bin


  用 ldd 命令查看一下 HTTPSQS 使用的动态链接库:
[root@ibm1 httpsqs-1.7]# ldd ./httpsqs
        linux-vdso.so.1 =>  (0x00007fff0ebff000)
        libevent-2.0.so.5 => /usr/local/libevent-2.0.12-stable/lib/libevent-2.0.so.5 (0x00007f5157979000)
        libtokyocabinet.so.9 => /usr/local/tokyocabinet-1.4.47/lib/libtokyocabinet.so.9 (0x00007f51576f6000)
        libz.so.1 => /lib64/libz.so.1 (0x00000038a1400000)
        libbz2.so.1 => /lib64/libbz2.so.1 (0x00000038a8800000)
        librt.so.1 => /lib64/librt.so.1 (0x00000038a2000000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00000038a1000000)
        libm.so.6 => /lib64/libm.so.6 (0x00000038a1800000)
        libc.so.6 => /lib64/libc.so.6 (0x00000038a0c00000)
        /lib64/ld-linux-x86-64.so.2 (0x00000038a0400000)

  发现,libevent 和 libtokyocabinet 使用的是我们指定 lib 路径中的动态链接库。



  HTTPSQS 的详细使用说明,请访问: http://blog.zyan.cc/httpsqs/





技术大类 » Cache与存储 | 评论(93) | 引用(0) | 阅读(73909)
裂帛服饰 Email Homepage
2011-10-14 16:19
很好的技术分享。。
购物控 Homepage
2011-10-16 21:36
好东东,收啦
wyc
2011-10-21 11:06
[root@vps httpsqs-1.7]# make
gcc -o httpsqs httpsqs.c prename.c -Wl,-rpath,/usr/local/libevent-2.0.12-stable/lib/:/usr/local/tokyocabinet-1.4.47/lib/ -L/usr/local/libevent-2.0.12-stable/lib/ -levent -L/usr/local/tokyocabinet-1.4.47/lib/ -ltokyocabinet -I/usr/local/libevent-2.0.12-stable/include/ -I/usr/local/tokyocabinet-1.4.47/include/ -lz -lbz2 -lrt -lpthread -lm -lc -O2 -g
httpsqs.c: In function ‘httpsqs_handler’:
httpsqs.c:350: error: ‘struct evhttp_request’ has no member named ‘uri_elems’
httpsqs.c:350: warning: assignment makes pointer from integer without a cast
make: *** [httpsqs] Error 1

博主你好,出现了这个问题。。
paladin
2011-10-22 21:54
确认一下你的/usr/local/libevent-2.0.12-stable是否安装成功,是类库没找到。
华隆交通信号灯 Email Homepage
2011-10-30 11:39
http://www.bzhldz.com/  学习.......
电视棒 Email Homepage
2011-11-8 11:49
一直都在学习,www.56tp.net
acd
2011-11-10 10:53
+号符在出队列后会转变成空格,这个问题博主是否发现了
白癜风的治疗 Homepage
2011-11-14 19:34
看不懂这些代码,好像全看懂了啊
白癜风的治疗 Homepage
2011-11-14 19:35
这技术很好学习了
厚工坊
2011-11-18 10:53
我转了,转到我的小站来的了。http://ww.gzhgf.com
奇谋网络 Email Homepage
2011-11-22 02:10
来您的博客看看,很佩服您,zan
louis vuitton uk Email Homepage
2011-11-22 17:09
This louis vuitton uk for sale belongs to the sounding just what are termed as Louis Vuitton vintage best sellers, many other products and services for the reason that range appearing companies.You will easily notice the unfold zippers of this coach outlet store online. That is the decoration. There are some inside pockets for you as well. They are easy to match your clothes and to carry.Let us inspire your inner beauty with fine christian louboutin sale. Purse the elegance in bridal wedding. Enjoy the fashion.
armani watches Email Homepage
2011-11-23 10:11
If you are looking for armani Bags, our armani watches Handbags Canada outlet store is your first choice. We promise Original Packing and Best Discount,3-5 Workdays To Your Door!If you buy bags and purses of the latest new designs from the louis vuitton outlet now, you can enjoy special discounts. What else are you waiting for?After you choose the right kind of plants and the size pot for the plant.
常德人才网 Email Homepage
2011-12-4 11:31
支持张哥
lee Email
2011-12-12 10:33
2.0.16 的 evhttp_pares_query_str ("test=0&tes2=1", headers);直接报段错误,难道我用错了,还是bug?
拇指玩 Homepage
2011-12-12 21:49
非常喜欢你的博客!收藏之。
小强 Email
2011-12-20 10:15
张兄,你好,我在使用httpsqs1.7的时候,发现一个可能是bug的问题,当我有一个线程不停的去抓去队列中的数据,然后另一边使用压力测试工具提交,siege -c 500 -r 2000 -f testurl.txt,队列应该存放100万数据,结果一共只有96万多,每次不等,丢个3-4万,有时候丢1万多,请问这是怎么回事?我后来又做了一次测试,我停止了那个取队列数据的线程,只用压力测试的工具存,结果一条都没丢,我非常的喜欢httpsqs,希望您能帮我解决一下这个问题。
我后来又做了一个测试siege -c 200 -r 2000 -f testurl.txt,并发200的时候并不会出现这个问题,是不是大并发的情况下会导致数据存储丢失呢?
开源哥
2011-12-21 16:19
TC B+Tree虽然顺序读写很快,但异常停止httpsqs和宕机时,消息会丢失。张老师在金山怎么应对这种情况呢?
wedding520 Email Homepage
2011-12-27 15:36
ワイドネックライン、'V'ネックやボートネックラインは、一般にキャップスリーブとドレスのために選ばれている。ボートスタイルのネックラインと幅広いネックラインのためには、オフショルダーのキャップスリーブを追加することができます。オフショルダーのウエディングドレスは、数年以来、結婚式の摩耗で人気のパターンになっても流行で、今日でもあります。カラードレス 格安.のこのスタイルで素敵に見える模様のオフショルダーの袖に行く同じシースのサテンからステッチ/オフショルダーのキャップスリーブの上に薄いと飾ったときに裾フレアのビットとシースのサテンのイブニングドレスとスパゲッティネックラインがすごい見えます。
清洗剂 Homepage
2012-2-4 10:56
来看看,支持下清洗剂www.dzhc188.com/
分页: 2/5 第一页 上页 1 2 3 4 5 下页 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]