咱們在使用一些開源程序以前,可能會使用ab工具在服務器或者本地進行一次性能評估,可是不少時候卻老是會以失敗了結,由於,服務器會拒絕你的ab工具發出的http請求, 出現 error: connection reset by peer, 這該怎麼辦呢?web
首先,爲了測試一個具備sql操做的頁面,一般須要登陸,這時候須要假裝成一個用戶來實現自動登陸,簡單的方法就是:在瀏覽器端登陸一個用戶,打開chrome的developer tool,將其中的cookie複製,用-H option來實現帶cookie的http請求,其他的併發任務交給ab工具,使得每一個http都攜帶session對應的cookie,若是這樣就ok了,基本上說明這個web app安全性有待考量,這也是初級使用者可能忽略的問題。sql
其次,若是假裝成登陸用戶,攜帶了cookie依然出現這個錯誤,那麼一般是因爲web app源碼中開啓了csrf防禦,針對假裝的請求作了過濾,這個問題也相對好解決,由於是開放源碼,咱們能夠打開源碼,找到這個web app的框架級的config文件,或者是 application級別的啓動器類,就能夠方便快速地找到這段程序,將csrf防禦關閉就能夠了。如下就以rails應用, 和 sails.js應用爲例,講述如何關閉csrf防禦。chrome
rails應用:代碼在controller目錄下的ApplicationController.rb文件,將其中的csrf保護函數protect_from_forgery中cookie.delete(auto_cookie_name)行註釋掉。或者將protect_from_forgery註釋掉,代碼以下:api
class ApplicationController < ActionController::Base include Redmine::I18n include Redmine::Pagination include RoutesHelper helper :routes class_attribute :accept_api_auth_actions class_attribute :accept_rss_auth_actions class_attribute :model_object layout 'base' protect_from_forgery def handle_unverified_request super #cookies.delete(autologin_cookie_name) end before_filter :session_expiration, :user_setup, :check_if_login_required, :set_localization rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token rescue_from ::Unauthorized, :with => :deny_access rescue_from ::ActionView::MissingTemplate, :with => :missing_template include Redmine::Search::Controller include Redmine::MenuManager::MenuController helper Redmine::MenuManager::MenuHelper def session_expiration if session[:user_id] if session_expired? && !try_to_autologin reset_session flash[:error] = l(:error_session_expired) redirect_to signin_url else #session[:atime] = Time.now.utc.to_i end end end
若是是sails.js web app, 那麼就更加簡單了,打開config目錄下,有一個csrf文件,將csrf設置爲false就能夠了。瀏覽器
在關閉了csrf以後,基本上ab測試就不會再出現error: connection reset by peer 了。安全
若是你對手頭沒有源碼的web app的性能測試感興趣,能夠參考個人其它文章。服務器
參考:cookie
檢查丟包利器dropwatch: http://blog.yufeng.info/archives/2497session
ulimit問題及其影響: http://blog.yufeng.info/archives/1380併發