编程小贴士

给你的编程提供小点子


HTTP的KeepAlive是开启还是关闭

      1、KeepAlive的概念与优势

HTTP的KeepAlive就是浏览器和服务端之间保持长连接,这个连接是可以复用的。当客户端发送一次请求,收到相应内容后,这个连接会保持一段时间,在该时间内的第二次就不需要再重新建立连接,就可以直接使用这次的连接来发送请求了,极大的提高了速度。

  2、KeepAlive的劣势

是不是所有网站都应该开启KeepAlive了?答案肯定是不是的。KeepAlive在增加访问效率的同时,也会增加服务器的压力。

  3、apache配置KeepAlive

apache通过配置KeepAlive和KeepAliveTimeout来控制KeepAlive,具体参数如下:

KeepAlive  On/Off            (可以设置开启On或者是关闭Off)

KeepAliveTimeout  10    (持久连接保持的时间,到时间会断开链接)

  4、案例说明(来源互联网):

假设 KeepAlive 的超时时间为 10 秒种,服务器每秒处理 50 个独立用户访问,那么系统中Apache的总进程数就是 10 * 50 = 500 个,如果一个进程占用 4M 内存,那么总共会消耗2G内存,所以可以看出,在这种配置中,相当消耗内存,但好处是系统只处理了 50次 TCP 的握手和关闭操作。

如果关闭 KeepAlive,如果还是每秒50个用户访问,如果用户每次连续的请求数为3个,那么 Apache 的总进程数就是 50 * 3 = 150 个,如果还是每个进程占用 4M 内存,那么总的内存消耗为600M,这种配置能节省大量内存,但是,系统处理了 150 次 TCP 的握手和关闭的操作,因此又会多消耗一些 CPU 资源。

  5、总结

  (1)如果内存和CPU都足够,开启和关闭KeepAlive对性能影响不大。

(2)如果考虑服务器压力,如果是静态页面,大量的调用js或者图片的话,建议开启KeepAlive;如果是动态网页,建议关闭KeepAlive。

71 Responses to “ HTTP的KeepAlive是开启还是关闭 ”

  1. chocopie说道:

    HGhWEg Wohh precisely what I was searching for, thankyou for putting up. Talent develops in tranquillity, character in the full current of human life. by Johann Wolfgang von Goethe.

  2. wow, awesome post.Really looking forward to read more. Really Cool.

  3. You can definitely see your enthusiasm in the work you write. The sector hopes for more passionate writers such as you who are not afraid to mention how they believe. All the time follow your heart.

  4. Click to read说道:

    Muchos Gracias for your article.Much thanks again. Awesome.

  5. You can certainly see your enthusiasm within the work you write. The sector hopes for more passionate writers like you who are not afraid to mention how they believe. All the time follow your heart.

  6. This site truly has all of the info I wanted about this subject and didn at know who to ask.

  7. what is mca说道:

    Way cool! Some very valid points! I appreciate you penning this write-up and the rest of the site is really good.

  8. Really appreciate you sharing this post.Much thanks again. Great.

  9. Airport taxi说道:

    Wow, superb blog layout! How long have you been blogging for? you made blogging look easy. The overall glance of your site is excellent, let alone the content material!

  10. The information and facts talked about within the write-up are several of the best obtainable

  11. pretty handy stuff, overall I imagine this is worth a bookmark, thanks

  12. Very Fascinating Blog! Thank You For This Weblog!

  13. Wow, what a video it is! Actually nice quality video, the lesson given in this video is actually informative.

  14. Citizenship说道:

    Just Browsing While I was surfing yesterday I saw a great article about

  15. Major thankies for the blog article.Thanks Again. Fantastic.

  16. Nwokolo说道:

    Thanks so much for the blog article.Thanks Again. Awesome.

  17. female scat porn说道:

    Thanks for ones marvelous posting! I truly enjoyed reading it, you are a great author.

  18. Thanks-a-mundo for the blog post.Thanks Again. Want more.

  19. Thanks for sharing, this is a fantastic post.Thanks Again. Cool.

  20. I?аАТ’аЂа†ll right away snatch your rss feed as I can at find your email subscription link or e-newsletter service. Do you ave any? Please allow me recognize so that I may just subscribe. Thanks.

  21. Mp3说道:

    Really appreciate you sharing this article. Cool.

  22. Wow, incredible blog format! How long have you been blogging for? The whole glance of your web site is fantastic, let well as the content!

  23. onlinecasino mac说道:

    Wow, great post.Really looking forward to read more. Awesome.

  24. Wow, fantastic blog format! How lengthy have you ever been blogging for? you made running a blog glance easy. The full look of your site is great, let alone the content material!

  25. play说道:

    Louis Vuitton For Sale ??????30????????????????5??????????????? | ????????

  26. Supermodel Elena说道:

    Oakley dIspatch Sunglasses Appreciation to my father who shared with me regarding this webpage, this web site is in fact awesome.

  27. Nanci说道:

    Thanks-a-mundo for the blog post.Really looking forward to read more. Great. sex photos

  28. write about here. Again, awesome website!

  29. Say, you got a nice article post.Thanks Again. Really Cool.

  30. Como tejer说道:

    Only a smiling visitant here to share the love (:, btw outstanding design and style. Justice is always violent to the party offending, for every man is innocent in his own eyes. by Daniel Defoe.

  31. try this说道:

    wow, awesome article.Much thanks again. Cool.

  32. to chuc su kien说道:

    Muchos Gracias for your article post. Really Great.

  33. There is noticeably a bundle to know about this. I assume you made certain nice factors in features also.

  34. hampton bay说道:

    interest. If you have any suggestions, please let me know.

  35. Your style is really unique in comparison to other people I ave read stuff from. Thanks for posting when you ave got the opportunity, Guess I all just bookmark this web site.

  36. Your style is very unique compared to other folks I ave read stuff from. Thanks for posting when you have the opportunity, Guess I all just bookmark this web site.

  37. Touche. Sound arguments. Keep up the good work.

  38. Supporting the publish.. all the best Truly beneficial perspective, many thanks for posting.. My web browsings seem complete.. thank you. So content to get located this article..

  39. Thanks-a-mundo for the blog article.Really thank you! Much obliged.

  40. Thank you for your article.Thanks Again. Cool.

  41. I was suggested this web site by my cousin. I am not sure whether this post is written by him as no one else know such detailed about my problem. You are incredible! Thanks!

  42. tututorials说道:

    With havin so much content do you ever run into any problems of plagorism or copyright infringement?

  43. ppg auto glass说道:

    It as really a great and helpful piece of information. I am glad that you shared this useful info with us. Please keep us up to date like this. Thank you for sharing.

  44. Loving the info on this web site , you have done great job on the posts.

  45. This genuinely answered my challenge, thank you!

  46. Just a smiling visitor here to share the love (:, btw outstanding pattern. Everything should be made as simple as possible, but not one bit simpler. by Albert Einstein.

  47. I truly appreciate this article post.Really looking forward to read more. Keep writing.

  48. you ave gotten an important weblog here! would you like to make some invite posts on my weblog?

  49. explore说道:

    Really enjoyed this blog.Much thanks again. Really Great.

  50. Perhaps You Also Make A lot of these Slip ups With the bag !

  51. just go to说道:

    if the buffalo in my head could speak german i would not know a god damm thing. What i do know is that the language of art is out of this world.

  52. This blog was how do you say it? Relevant!! Finally I have found something that helped me. Appreciate it!

  53. This very blog is really interesting and besides amusing. I have discovered helluva helpful things out of this blog. I ad love to visit it again and again. Thanks a bunch!

  54. Im thankful for the blog article.Thanks Again. Keep writing.

  55. Wow, what a video it is! Truly fastidious quality video, the lesson given in this video is really informative.

  56. twitter说道:

    This is one awesome article post.Really looking forward to read more. Keep writing.

  57. There is a psychological vitamin between the virtual job and social functioning in following these components.

  58. for more info说道:

    It as difficult to find well-informed people on this subject, but you sound like you know what you are talking about! Thanks

  59. check说道:

    I will immediately grab your rss as I can not find your email subscription link or newsletter service. Do you ave any? Please let me realize so that I may subscribe. Thanks.

  60. I truly appreciate this article post. Keep writing.

  61. Just Browsing While I was surfing yesterday I noticed a excellent post about

  62. Say, you got a nice blog post.Much thanks again.

  63. web说道:

    You can certainly see your enthusiasm in the work you write. The world hopes for more passionate writers such as you who aren at afraid to say how they believe. All the time go after your heart.

  64. I see in my blog trackers significant traffic coming from facebook. My blog is not connected with facebook, I don at have an account there, and I can at see, who posts the linksany ideas?.

  65. launchpad mk2说道:

    Really enjoyed this article post. Awesome.

  66. Im obliged for the blog article.Much thanks again. Fantastic.

  67. This blog was how do you say it? Relevant!! Finally I have found something which helped me. Thank you!

  68. go here说道:

    very few internet sites that happen to become comprehensive below, from our point of view are undoubtedly very well worth checking out

  69. What as up, this weekend is pleasant for me, as this moment i am reading this wonderful informative piece of writing here at my home.

  70. yeezy boost 350说道:

    Thanks a lot for providing individuals with an extremely terrific possiblity to read from here. It is always so beneficial and as well , stuffed with a good time for me and my office co-workers to search your blog the equivalent of thrice a week to find out the fresh tips you have got. Of course, I am at all times astounded concerning the unique strategies you give. Some two facts in this article are unquestionably the most efficient I’ve had.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>