gearman 源码学习笔记1

   1年前和阿里的大牛们聊天。被告知etao网使用 gearman 做分布式的中间件使访问达到了 百万的qps。从次对gearman有了初步的认识。之前主导项目的时候决定使用gearman做 分布式。 但是当压力到达一定级别的时候。

gearman 产生了大量的 close wait 导致大量的worker 无法连到 gearman。试了各种办法无法解决从而产生了研究gearman源码的冲动。不说废话啦,从main说起。


首先命令行参数解析 gearman 竟然用boost_program.so 真tm蛋疼用这么一个小功能竟然要装个boost

  boost::program_options::options_description general("General options");

  general.add_options()
  ("backlog,b", boost::program_options::value(&backlog)->default_value(32),
   "Number of backlog connections for listen.")

  ("daemon,d", boost::program_options::bool_switch(&opt_daemon)->default_value(false),
   "Daemon, detach and run in the background.")

  ("exceptions", boost::program_options::bool_switch(&opt_exceptions)->default_value(false),
   "Enable protocol exceptions by default.")

  ("file-descriptors,f", boost::program_options::value(&fds),
   "Number of file descriptors to allow for the process (total connections will be slightly less). Default is max allowed for user.")

  ("help,h", "Print this help menu.")

在参数解析时比较重要的一个逻辑就是

if (threads == 0)
  {
    uint32_t number_of_threads= libtest::number_of_cpus();

    if (number_of_threads > 4)
    {
      threads= number_of_threads;
    }
  }
当没有指定-t的时候 默认工作线程的数量是cpu的数量,而当核数少于4个的时候将会变成单线程程序。当然大家都应该知道在 没有复杂业务逻辑和持久化要求的情况下。单纯提高线程数其实对于并发是没有太多帮助的。

 下回将细说gearman如何利用libevent架构网络环境。





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值