[文章作者:张宴 本文版本: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与存储 | 评论(97) | 引用(0) | 阅读(75644)
North Face Outlet Email Homepage
2012-11-13 22:30
<a href="http://www.us2012northfacejackets.com/">North Face Jackets</a> is becoming more and more important to everyone as the winter is around the corner. Buy north face winter jacket from <a href="http://www.us2012northfacejackets.com/">North Face Outlet</a> online store can save your much money. <a href="http://www.us2012northfacejackets.com/">Discount North Face</a> jacket from our store is your best choice for winter.
Christian Louboutin Outlet Email Homepage
2012-11-13 22:30
Thousand kinds of fashion red bottom shoes are on great discount in <a href="http://www.womenlouboutinshoes.com/">Christian Louboutin Outlet</a> store. No matter who can find the right style CL shoes she like from our store. You will totally fall in love with our <a href="http://www.womenlouboutinshoes.com/">Cheap Christian Louboutin</a> shoes.
你好 Email
2013-3-25 18:33
你好,因为用b+树,所以几乎所有的查询都是logn,最频繁的操作是enqueue,和dequeue,但是在这两个操作中都要执行httpsqs_now_(get|put)pos,而这个操作都会调用3-5次查询或者更新操作,如果把 maxqueue_num,queue_put_value,queue_get_value在内存中维护一份,在定期sync和子进程结束时sync到磁盘,虽然这样会有一定的丢数据的风险,但是性能定会大大提高
STV
2013-4-11 12:06
关于数据中带“+”会被替换还成空格的问题,昨天使用的时候碰到,我是用BASE64编码过的数据, 看来提交前需要自己做下URL ENCODING比较保证
磨延城 Email Homepage
2013-10-21 18:03
磨途歌学习了,先做个记号,以后肯定用得上
django Email Homepage
2013-11-30 19:14
Uggs Sale the ideal idea Coach Outlet Online  enough time to search for many of reduction Ugg boot. Like big portions? If you began ready your apartment, Coach Outlet  it's always best to consider the most effective way direct to the stage it could be to utilise your inventory throughout Coach Factory Outlet  concern, or maybe you basically won't destination stuff not enough.we're anti- whitening tray because Coach Outlet Online  i will be enjoy just get germ dog breeders
变压器 Homepage
2014-7-28 16:58
呵呵,不错,谢谢分享
林作鸿 Email
2015-2-2 12:38
$ makegcc -o httpsqs httpsqs.c prename.c -Wl,-rpath,/usr/local/libevent-2.0.21/lib/:/usr/local/tokyocabinet-1.4.47/lib/ -L/usr/local/libevent-2.0.21/lib/ -levent -L/usr/local/tokyocabinet-1.4.47/lib/ -ltokyocabinet -I/usr/local/libevent-2.0.21/include/ -I/usr/local/tokyocabinet-1.4.47/include/ -lz -lbz2 -lrt -lpthread -lm -lc -O2 -gld: library not found for -lrtclang: error: linker command failed with exit code 1 (use -v to see invocation)make: *** [httpsqs] Error 1mac pro 下编译报错
steven Email Homepage
2015-3-20 05:30
samy Email Homepage
2015-3-20 23:10
,先做个记号,以后肯定用得上 asphalt 8 hack
nih Email
2015-8-8 12:45
请问主次热备如何实现
run3 Email
2019-4-26 11:08
The article is very good, the content is specific and easy to understand. The article helped me a lot. thanks a lot. fnaf
JohnTallman Email
2019-6-3 17:32
HTTP通信包括将方法(动词)应用于URL。 这个应用程序的结果应该是 - 惊喜!  - 动词中写的是什么。 也就是说,GET返回资源表示,DELETE删除,依此类推

essays for sale
Psychology Writing Services Online Homepage
2020-1-28 13:25
Obtaining psychology writing services is fulfilling for most students who have to struggle with deadlines on psychology coursework writing services and psychology homework writing services.
Religion Writing Services Homepage
2020-2-14 16:42
Obtaining custom religion services online is fulfilling for most students who have to struggle with deadlines on college religion writing services and professional religion writing services.
Nursing Assignment Writing Services Email Homepage
2020-2-14 21:56
Students who seek Nursing Assignment Writing Services Online from a writing company are guaranteed of getting good grades for their Nursing Assignment Writing Help and Online Nursing Assignment Writing Services that are free from grammatical errors.
dorcassmith Homepage
2020-2-21 19:54
Many students opt to buy psychology writing services since most writing companies are good in online psychology assignment help services and psychology coursework writing services.
Caroline
2020-3-16 15:35
You nicely explaining with us about latest update in HTTPSQS 1.7. I would like to say thanks to an author for wonderfully explained post with us. Keep sharing another informative posts.Caroline, http://www.personalstatementfolks.co.uk/graduate-personal-statement/
Caroline Email
2020-3-16 15:36
You nicely explaining with us about latest update in HTTPSQS 1.7. I would like to say thanks to an author for wonderfully explained post with us. Keep sharing another informative posts.Caroline, http://www.personalstatementfolks.co.uk/graduate-personal-statement/
分页: 4/5 第一页 上页 1 2 3 4 5 下页 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]