HTTP KeepAlive,开启还是关闭

HTTP协议中的KeepAlive属性 KeepAlive出现的原因: 当一个客户端向服务器发送http请求时,两者之间会建立一个tcp连接,然后服务器发回响应信息同时关闭连接。如果请求的的页面中含有别的资源连接,比如图片、flsah等,就会再次创建连接。KeepAlive的作用就是在第一次创建连接时,服务器会把这个tcp连接保持一段时间(服务器端会有一个keepaliveTime的最大时间,超过时间就断开连接)。这样就不会频繁的去建 阅读详情

所谓「HTTP Keep-Alive」,在维基百科里称为「HTTP Persistent Connection」,说白了就是复用HTTP连接,如此一来理论上客户端的用户体验会更流畅,但是与之相对服务端不得不维持大量的连接。开启还是关闭,这是个问题。

   一个经常用来讲解HTTPKeepAlive的例子一般是这样描述的:当我们访问一个包含了若干个图片的网页时,如果HTTPKeepAlive是关闭的,那么页面中每一个图片都会发起是一次连接请求;但是如果HTTPKeepAlive是开启的,那么因为可以复用HTTP连接,所以可以节省很多不必要的开销。

   听起来不错!不过现在可不是用猫上网的年代了,当今高带宽低延迟的网络让建立HTTP连接不再是什么难事儿,此时访问一个包含了若干个图片的网页时,与其打开一个连接然后串行的请求图片,不如打开多个连接然后并行的请求图片,事实上现代浏览器也都是这么干的,最佳实战甚至倡导通过多域名进一步提升并发数。

   此外,再让我们看看某台开启了KeepAlive的Nginx服务器的Status结果:

shell> curl -s http://127.0.0.1/status
Active connections: 95896
server accepts handled requests
 66542336512 66542336512 67713042963
Reading: 1945 Writing: 82 Waiting: 93869

   其中,各项结果的含义如下:

  • Active connections: number of all open connections

  • Server accepts handled requests: nginx accepted 66542336512 connections, handled 66542336512 connections (no one was closed just it was accepted), and handles 67713042963 requests

  • Reading: nginx reads request header

  • Writing: nginx reads request body, processes request, or writes response to a client

  • Waiting: keep-alive connections, actually it is active - (reading + writing)

       实际复用HTTP连接的效果如何呢:

    67713042963 / 66542336512 = 1.01 requests per connection

       额滴神啊,基本等同于没用!为什么会这样?因为这是一台WebService服务器,客户端只是偶尔访问一次,此时的KeepAlive连鸡肋都不如,为了服务器的性能,关闭它吧!

       …

       HTTPKeepAlive,开启还是关闭,大家不妨结合自己的客观情况重新思考一下。

HTTP keep-alive和TCP keepalive的区别,你了解吗? 1、从文中找出我的IP 2、http请求中是客服端还是服务端主动关闭的tcp连接? 请阅读到最后的彩蛋部分 HTTP和TCP都是老生常谈的知识点,本文不进行铺开赘述。我们可能在HTTP和TCP中都听说“长连接”的说法,也听过HTTP中有keep-alive,TCP中有keepalive。那么,HTTP和TCP的长连接有何区别?HTTP中的keep-alive和TCP中keepalive又有什么区别? Tips:HTTP中是keep-alive,TCP中是keepalive,HTTP中是带中划线的。. 阅读详情

相关推荐

行人重识别(ReID)基础知识入门

行人重识别(Person re-identification)主要目的是针对出现在监控摄像头内的某个目标行人,准确快速地从监控网络其他摄像头内的大量行人中将这个目标行人标识出来。如图所示一个区域有多个摄像头拍摄视频序列,ReID的要求对一个摄像头下感兴趣的行人,检索到该行人在其他摄像头下出现的所有图片。

用于记录 1万+

HTTP Connection 头(header)说明:keep-alive和closer的区别

HTTP Connection 头(header)说明:keep-alive和closer的区别 前言 在http请求时,我们一般会在request header 或 response header 中看到”Connection:Keep-Alive”或 “Connection:close”,这里具体的含义是有关http 请求的是否保持长连接,即链接是否复用,每次请求是复用已建立好的请求,还是重新...

海渊_haiyuan的博客 5万+

SRC漏洞挖掘实战指南:从零入门到月入过万的网络安全副业

网络安全的核心在于识别和修复系统缺陷,其中逻辑漏洞与信息泄露是常见的安全风险。其原理在于应用程序在业务逻辑设计或数据处理过程中存在缺陷,导致未授权访问或敏感数据暴露。掌握这些技术对于构建安全的应用体系至关重要,不仅能有效防范攻击,也为安全研究人员提供了将技术能力变现的合法途径。在漏洞赏金(Bug Bounty)和SRC(安全应急响应中心)等应用场景中,白帽子通过系统化的测试方法,挖掘此类漏洞,既能获得经济回报,又能积累宝贵的实战经验。本文聚焦于逻辑漏洞与信息泄露的实战挖掘技巧,为初学者提供清晰的入门路径和效

weixin_28568819的博客 351

HTTP的KeepAlive是开启还是关闭?

HTTP的KeepAlive开启可以极大的提高了速度,但是开启又会增加服务器的压力,KeepAlive到底是应该开启还是关闭?

PHP学习与交流 3929

准静态电磁场

叠加法 缺点:对于连续分布的电荷,叠加法的计算比较困难 虚位移法 概念 广义坐标:确实系统中导体形状、尺寸与位置的一组独立几何量。 广义力:企图改变某一广义坐标的力。 功:广义力乘上由它引起的广义坐标的改变量。 公式 ...

qq_35912930的博客 1860

【算法设计与分析】期末复习题(超详细)

刚刚整理了一下电脑的文件,发现了这份上学期的算法设计与分析期末复习题,有需要的文后自取。

a1234567822的博客 6614

客户端禁用Keep-Alive, 服务端开启Keep-Alive,会怎么样?

最近部署的web程序,服务器上出现不少time_wait的tcp连接状态,占用了tcp端口,花费几天时间排查。 之前我有结论:HTTP keep-alive 是在应用层对TCP...

qq_30236895的博客 1738

基于carsim与Simulink联合仿真的车辆换道轨迹规划与轨迹跟踪模型

PID_反步控制_滑膜控制三种四旋翼无人机轨迹跟踪控制算法仿真 附带对应的说明文档,提供建模过程与仿真结果文献(英文)➕PPT 描述:采用的同一种参考轨迹,都是三维仿真 三种控制方法: [1]PID控制、[2]反步控制、[3]滑膜控制(三个仿真模型) 每个仿真均应用了同一种轨迹路径,直接运行即可出三维图,可以实现四旋翼无人机轨迹的跟踪

2501_90804007的博客 1085

mySQL的学记录day2

mySQLmySQLmySQL的学记录—day2day2day2 1.去除重复记录 使用 distinct 关键字,该关键字只能用在字段的前面,如果用在多个字段的前面,则表示对于多个字段进行去重,若多个字段中存在一个不相同,则视为不同。 2.连接查询。 分类: 1.内连接: 等值连接,非等值连接,自连接。 2.外连接: 左外连接,右外连接。 3.全连接。 连接查询中的笛卡尔积现象: 每个表的字段会依次与另一个表中字段进行匹配,匹配次数就是两者个数的乘积数。 等值连接: select 字段1,字段2 fro

Harris-H的博客 647

CIC-IDS数据集特征介绍

###1、简介 通信安全机构(CSE)与加拿大网络安全研究所(CIC)合作项目,该项目对自1998年以来现有的11个数据集的评估表明,大多数数据集(比如经典的KDDCUP99,NSLKDD等)已经过时且不可靠。其中一些数据集缺乏流量多样性和容量,一些数据集没有涵盖各种已知的攻击,而另一些数据集将数据包有效载荷数据匿名化,这不能反映当前的趋势。有些还缺少特征集和元数据。 CIC-IDS-2017数据集包含良性和最新的常见攻击,类似真实世界数据(PCAPs)。 它的数据采集截至2017...

蓝亚之舟的博客 3万+

从时序参数到电压供给:TTL(RGB)液晶屏驱动调试全解析

本文全面解析TTL(RGB)液晶屏驱动调试的关键技术,从时序参数配置到电压供给系统搭建,详细介绍了同步信号参数、寄存器配置技巧以及升压电路设计。通过实战案例和常见故障分析,帮助工程师快速掌握液晶显示屏调试方法,提升开发效率。

weixin_30588675的博客 247

php http keep alive,HTTP的KeepAlive是开启还是关闭?

1、KeepAlive的概念与优势HTTP的KeepAlive就是浏览器和服务端之间保持长连接,这个连接是可以复用的。当客户端发送一次请求,收到相应内容后,这个连接会保持一段时间,在该时间内的第二次就不需要再重新建立连接,就可以直接使用这次的连接来发送请求了,极大的提高了速度。2、KeepAlive的劣势是不是所有网站都应该开启KeepAlive了?答案肯定是不是的。KeepAlive在增加访问效...

weixin_28974985的博客 387

Google Cameraserver 看门狗CameraServiceWatchdog超时crash原理分析

本文分析了Android CameraServiceWatchdog机制的工作原理。该看门狗用于监控相机服务关键操作(如close、flush)的超时情况,通过定时器线程检测阻塞问题。文章详细讲解了Watchdog的初始化流程、使能方式、内部定时器机制(默认周期100ms,650次循环触发超时),并提供了configureStreams阶段的客制化实现方案。当检测到超时,Watchdog会触发abort生成tombstone日志,便于调试分析。

1130

关于HTTP协议中的KeepAlive属性

首先就看一下KeepAlive出现的原因吧: 当一个客户端向服务器发送http请求时,两者之间会建立一个tcp连接,然后服务器发回响应信息同时关闭连接。如果请求的的页面中含有别的资源连接,比如图片、flsah等,就会再次创建连接。KeepAlive的作用就是在第一次创建连接时,服务器会把这个tcp连接保持一段时间(服务器端会有一个keepaliveTime的最大时间,超过时间就断开连接)。这样就...

tianli1987917的博客 548

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

http包中keepalive问题

[TOC] 开启keepalive 测试之前,需要把client作为全局变量,公用客户端 //定义客户端,然后关闭keepalive var client = http.Client{ Transport: &http.Transport{ DisableKeepAlives: false, //当需要频繁发生请求的时候,需要把keepalive关闭掉。...

kismile 1138

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: WEB安全:文件上传漏洞
下一篇: Web性能压力测试工具之WebBench详解
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值