Sunshow Life
回到最初的美好
Browse: Home / 2010 / 三月 / libcurl与CLOSE_WAIT

libcurl与CLOSE_WAIT

By Sunshow on 2010-03-02

调用libcurl下载,然后使用netstat查看发现有大量的TCP连接保持在CLOSE_WAIT状态
查看libcurl的文档说明,有这样一个选项:

CURLOPT_FORBID_REUSE

Pass a long. Set to 1 to make the next transfer explicitly close the connection when done. Normally, libcurl keeps all connections alive when done with one transfer in case a succeeding one follows that can re-use them. This option should be used with caution and only if you understand what it does. Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior).

也就是说,默认情况下libcurl完成一个任务以后,出于重用连接的考虑不会马上关闭
如果没有新的TCP请求来重用这个连接,那么只能等到CLOSE_WAIT超时,这个时间默认在7200秒甚至更高,太多的CLOSE_WAIT连接会导致性能问题

解决方法:

curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 1);

最好再修改一下TCP参数调低CLOSE_WAIT和TIME_WAIT的超时时间

标签:libcurl, TCP, 下载

Relatd Posts:
  • μTorrent 1.6.1 (build 488) released (1)
  • Firefox 3 下载日 (1)
  • CSS Sprites样式生成工具 (0)
  • IE8正式发布 (1)

Posted in C, Network | Tagged libcurl, TCP, 下载

« Previous Next »
GMail & GTalk

Search

Pages

  • Archives
  • Documents
  • Gallery
  • Links
  • Projects
  • Tips

Tweets

  • 求推荐PHP开发、产品助理、Web设计师,sunshow#gmail.com http://t.co/w6q70kL6 2012-04-14
  • @feuvan 这么复杂的操作是做什么的 2012-03-12
  • 污染基本靠吹 2012-02-22
  • 发现我的timeline一天也更新不了一页 2012-02-21
  • @tualatrix VNC view only 2012-02-21
  • More updates...

Categories

  • Arsenal
  • C
  • Delphi
  • Game
  • Java
  • Life
  • Linux
  • Mac OS X
  • Network
  • PHP
  • Software
  • WebDev
  • WordPress

Recommend

  • 乐和彩

Blogroll

  • LIfe iS StRUGgle
  • bianbian coding life
  • 不和谐因素
  • CuteFool.Net – 南子

Recent Comments

  • hhdem 发表在《2011我的梦》
  • bianbian 发表在《IE6提交表单到动态添加的iframe》
  • weedding dresses 发表在《Get Recent Comments 中文改良版》
  • qatang 发表在《Tomcat请求HTTPS的注意事项》
  • surmise 发表在《[WordPress]对不同域名使用不同的主题》

Meta

  • 登录
  • 文章 RSS
  • 评论 RSS
  • WordPress.org

Tag Cloud

无线 plugin 仙剑 更新 珊瑚虫 输入法 安装 PHP 工作 轩辕剑 下载 QQ 字体 feed 中国 Delphi 插件 主题 Linux bug WordPress 冠军杯 搬家 手机 web javascript 生活 css firefox 上海 生日 Java 电影 Arsenal ie google 阿森纳 Tomcat 拼音 图片 ubuntu 互联网 windows html 中文