我個人認為一個優秀的軟件工程師必須掌握一定的測試技能。可能有的開發工程師認為測試是測試工程師的事情,不是開發工程師的事情。這種開發工程師是缺一條腿的,離開了測試工程師,你如何證明你的程序沒有問題。
下面是我這兩天搜集的性能測試工具,如果大家知道別的工具,可以在回復中分享出來。
Web Bench
Web Bench is very simple tool for benchmarking WWW or proxy servers. Uses fork() for simulating multiple clients and can use HTTP/0.9-HTTP/1.1 requests. This benchmark is not very realistic, but it can test if your HTTPD can realy handle that many clients at once (try to run some CGIs) without taking your machine down. Displays pages/min and bytes/sec. Can be used in more aggressive mode with -f switch.
Web Bench是一個簡單的web或者web代理服務的基准測試工具。(它)使用fork()模擬多個客戶端並且可以發起HTTP/0/9-HTTP/1.1的請求。這個基准測試不是非常符合實際情況,但是可以測試出你的HTTP服務是否可以處理多個客戶同時訪問而不會把你的機器弄掛掉。這個工具可以獲得服務的兩個指標:每分鍾響應請求數量(pages/min)和每秒鍾傳輸數據量(bytes/sec)。使用-f選項可以運行在主動模式下(不等待服務器響應直接發送下一個請求)。
安裝方法參考:(總結)Web性能壓力測試工具之WebBench詳解
命令參數:
使用webbench測試elong,taobao,baidu的結果(可能受電腦性能、網絡的因素影響):
ab - Apache HTTP server benchmarking tool
ab is a tool for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server. It is designed to give you an impression of how your current Apache installation performs. This especially shows you how many requests per second your Apache installation is capable of serving.
ab命令會創建很多的並發訪問線程,模擬多個訪問者同時對某一URL地址進行訪問。它的測試目標是基於URL的,因此,既可以用來測試Apache的負載壓力,也可以測試nginx、lighthttp、tomcat、IIS等其它Web服務器的壓力。ab命令對發出負載的計算機要求很低,既不會占用很高CPU,也不會占用很多內存,但卻會給目標服務器造成巨大的負載,其原理類似CC攻擊。自己測試使用也須注意,否則一次上太多的負載,可能造成目標服務器因資源耗完,嚴重時甚至導致死機。
網上有些文章說安裝apache2后一般情況下在Apache的bin目錄下。我在Ubunut 14.04上測試,並不是這樣。要在Ubuntu上使用ab,需要apache2-utils。
ab的用法參考:ab - Apache HTTP server benchmarking tool,(總結)Web性能壓力測試工具之ApacheBench(ab)詳解
Siege
Siege is an http load testing and benchmarking utility. It was designed to let web developers measure their code under duress, to see how it will stand up to load on the internet. Siege supports basic authentication, cookies, HTTP and HTTPS protocols. It lets its user hit a web server with a configurable number of simulated web browsers. Those browsers place the server “under siege.”
Siege(英文意思是圍攻)是一個壓力測試和評測工具,設計用於WEB開發這評估應用在壓力下的承受能力:可以根據配置對一個WEB站點進行多用戶的並發訪問,記錄每個用戶所有請求過程的相應時間,並在一定數量的並發訪問下重復進行。 Siege 支持基本的認證,cookies, HTTP 和 HTTPS 協議。
Siege的安裝和用法可以參考:Siege Manual,Using Siege to Tune Apache on GNU/Linux,(總結)Web性能壓力測試工具之Siege詳解,壓力測試工具siege的用法
我的Ubuntu 14.04上的使用如下:
測試本地的tomcat的測試結果:
Apache JMeter
Apache JMeter是一個專門為運行和服務器裝載測試而設計的、100%的純Java桌面運行程序。原先它是為Web/HTTP測試而設計的,但是它已經擴展以支持各種各樣的測試模塊。它和用於HTTP和SQL數據庫(使用JDBC)的模塊一起運送。它可以用來測試靜止資料庫或者活動資料庫中的服務器的運行情況,可以用來模擬對服務器或者網絡系統加以重負荷以測試它的抵抗力,或者用來分析不同負荷類型下的所有運行情況。它也提供了一個可替換的界面用來定制數據顯示,測試同步及測試的創建和執行。
JMeter的工作原理:JMeter可以作為Web服務器與瀏覽器之間的代理網關,以便捕獲瀏覽器的請求和Web服務器的響應,這樣就很容易地生成性能測試腳本,有了性能測試腳本,JMeter就可以通過線程組來模擬真實用戶對Web服務器的訪問壓力,這與LoadRunner的工作原理基本一致。
下面是JMeter的官方簡介:
The Apache JMeter™ desktop application is open source software, a 100% pure Java application designed to load test functional behavior and measure performance. It was originally designed for testing Web Applications but has since expanded to other test functions.
What can I do with it?
Apache JMeter may be used to test performance both on static and dynamic resources (Files, Web dynamic languages - PHP, Java, ASP.NET, etc. -, Java Objects, Data Bases and Queries, FTP Servers and more). It can be used to simulate a heavy load on a server, group of servers, network or object to test its strength or to analyze overall performance under different load types. You can use it to make a graphical analysis of performance or to test your server/script/object behavior under heavy concurrent load.
What does it do?
Apache JMeter features include:
- Ability to load and performance test many different server/protocol types:
- Web - HTTP, HTTPS
- SOAP
- FTP
- Database via JDBC
- LDAP
- Message-oriented middleware (MOM) via JMS
- Mail - SMTP(S), POP3(S) and IMAP(S)
- MongoDB (NoSQL)
- Native commands or shell scripts
- TCP
- Complete portability and 100% Java purity .
- Full multithreading framework allows concurrent sampling by many threads and simultaneous sampling of different functions by separate thread groups.
- Careful GUI design allows faster Test Plan building and debugging.
- Caching and offline analysis/replaying of test results.
- Highly Extensible core:
- Pluggable Samplers allow unlimited testing capabilities.
- Several load statistics may be choosen with pluggable timers .
- Data analysis and visualization plugins allow great extensibility as well as personalization.
- Functions can be used to provide dynamic input to a test or provide data manipulation.
- Scriptable Samplers (BeanShell, BSF-compatible languages and JSR223-compatible languages)
JMeter的用戶手冊:http://jmeter.apache.org/usermanual/index.html
推薦一本書籍:《零成本實現Web性能測試》
JMeter的腳本錄制工具:Badboy
Web Polygraph
Web Polygraph這個軟件也是一個用於測試WEB性能的工具,這個工具是很多公司的標准測試工具,包括微軟在分析其軟件性能的時候,也是使用這個工具做為基准工具的。很多招聘測試員的廣告中都注明需要熟練掌握這個測試工具。
Web Polygraph is a freely available performance testing tool for caching proxies, origin server accelerators, L4/7 switches, content filters, and other Web intermediaries. Polygraph's features include:
- high-performance HTTP clients and servers
- realistic HTTP, FTP and SSL traffic generation
- HTTP and SOCKS5 proxy support, with chaining
- HTTP Basic, NTLM, and Negotiate proxy authentication
- LDAP-friendly generation of user credentials
- flexible content simulation
- ready-to-use standard workloads for benchmarking
- powerful domain-specific configuration language
- portable open-source implementation
- friendly commercial support
TCPCopy
Although the real live flow is important for the test of Internet server applications, it is hard to simulate it as online environments are too complex. To support more realistic testing of Internet server applications, we propose a live flow reproduction tool – TCPCopy, which could generate the test workload that is similar to the production workload. TCPCopy consists of two components: the TCPCopy Client (tcpcopy) and the TCPCopy Server (intercept). The TCPCopy Client (tcpcopy) is deployed on the production system and it copies live flow data, does necessary modifications and sends them to the test system in real-time. The TCPCopy Server (intercept) is deployed on the test system and it returns necessary response information to the TCPCopy Client (tcpcopy). To the test server, the reproduced workload is just from end-users. Currently, TCPCopy has been widely used by companies in China.
TCPCopy has little influence on the production system except occupying additional CPU, memory and bandwidth. Moreover, the reproduced workload is similar to the production workload in request diversity, network latency and resource occupation.
Traditional architecture
Advanced architecture
Tsung
Tsung is an open-source multi-protocol distributed load testing tool
It can be used to stress HTTP, WebDAV, SOAP, PostgreSQL, MySQL, LDAP and Jabber/XMPP servers. Tsung is a free software released under the GPLv2license.
The purpose of Tsung is to simulate users in order to test the scalability and performance of IP based client/server applications. You can use it to do load and stress testing of your servers. Many protocols have been implemented and tested, and it can be easily extended.
It can be distributed on several client machines and is able to simulate hundreds of thousands of virtual users concurrently (or even millions if you have enough hardware ...).
Tsung is developed in Erlang, an open-source language made by Ericsson for building robust fault-tolerant distributed applications.
curl-loader
curl-loader (also known as "omes-nik" and "davilka") is an open-source tool written in C-language, simulating application load and application behavior of thousands and tens of thousand HTTP/HTTPS and FTP/FTPS clients, each with its own source IP-address. In contrast to other tools curl-loader is using real C-written client protocol stacks, namely, HTTP and FTP stacks of libcurl and TLS/SSL of openssl, and simulates user behavior with support for login and authentication flavors.
The goal of the project is to deliver a powerful and flexible open-source testing solution as a real alternative to Spirent Avalanche and IXIA IxLoad.
The tool is useful for performance loading of various application services, for testing web and ftp servers and traffic generation. Activities of each virtual client are logged and collected statistics includes information about resolving, connection establishment, sending of requests, receiving responses, headers and data received/sent, errors from network, TLS/SSL and application (HTTP, FTP) level events and errors.
Virtual clients are grouped together to the so-called batches of clients, performing the same sort of activities, like:
- authentication login;
- user activity simulation by fetching several URLs with configurable timeouts in between;
- logoff.
The tool can be easily extended to generate sftp, telnet, tftp, ldap, ssh, scp etc other application protocols, supported by the great libcurl library.
Grinder
Grinder是一個開源的JVM負載測試框架,它通過很多負載注射器來為分布式測試提供了便利。 支持用於執行測試腳本的Jython腳本引擎HTTP測試可通過HTTP代理進行管理。根據項目網站的說法,Grinder的 主要目標用戶是“理解他們所測代碼的人——Grinder不僅僅是帶有一組相關響應時間的‘黑盒’測試。由於測試過程可以進行編碼——而不是簡單地腳本 化,所以程序員能測試應用中內部的各個層次,而不僅僅是通過用戶界面測試響應時間。
LoadRunner(商業軟件)
LoadRunner 是一種預測系統行為和性能的工業標准級負載測試工具。通過以模擬上千萬用戶實施並發負載及實時性能監測的方式來確認和查找問題,LoadRunner 能夠對整個企業架構進行測試。通過使用LoadRunner , 企業能最大限度地縮短測試時間, 優化性能和加速應用系統的發布周期。企業的網絡應用環境都必須支持大量用戶,網絡體系架構中含各類應用環境且由不同供應商提供軟件和硬件產品。難以預知的用戶負載和愈來愈復雜的應用環境使公司時時擔心會發生用戶響應速度過慢, 系統崩潰等問題。這些都不可避免地導致公司收益的損失。Mercury Interactive 的 LoadRunner 能讓企業保護自己的收入來源, 無需購置額外硬件而最大限度地利用現有的IT 資源, 並確保終端用戶在應用系統的各個環節中對其測試應用的質量, 可靠性和可擴展性都有良好的評價。LoadRunner 是一種適用於各種體系架構的自動負載測試工具, 它能預測系統行為並優化系統性能。LoadRunner 的測試對象是整個企業的系統, 它通過模擬實際用戶的操作行為和實行實時性能監測, 來幫助您更快的查找和發現問題。此外,LoadRunner 能支持廣范的協議和技術, 為您的特殊環境提供特殊的解決方案。kylinpet(國產商業工具)
kylinPET(performance emulation tool,麒麟寵物)是一款功能強大的性能測試工具;界面友好、操作方便,資源占用率低;自帶TCP/IP協議棧,支持虛擬大量IP;支持IPv4、IPv6的多種業務測試;支持WEB/WebService業務與Flex(HTTP)、IMS業務(SIP)、IPTV業務(RTSP/IGMP/MLD)、XMPP、Socket業務、數據庫、JMS、FTP/SFTP、WEB視頻(包括FLV/MP4/HTTP Live Streaming/HTTP Smooth Streaming/HTTP Dynamic Streaming)、WebSocket、JAVA;支持多種協議組合。
總結一些性能測試的做法
- 為了減少網絡延遲和帶寬限制對性能測試的影響,最好在內網進行測試。
- 性能測試一般在優化前和優化后,測試兩輪,這樣能夠比較出優化前后的效果。
- 性能測試最好跑的時間長一些,觀察程序是否存在內存泄漏、資源未釋放等問題。
- 有的公司為了避免影響線上環境,只在測試環境做性能測試。我所在的公司性能測試一般在線下線上都會做,線上做性能測試可以了解生產環境的性能情況。