<p>当运行多个线程时,cPython不会从多个内核中获得优势。这意味着,基本上,你将只有一个核心做测试工作。</p>
<p>有专门的工具来做你想做的事。我建议两个:</p>
<p><a href="http://pypi.python.org/pypi/funkload/" rel="noreferrer"><strong>FunkLoad</strong></a>是一个用Python编写的功能性和负载web测试程序,其主要用例是:</p>
<ul>
<li>web项目的功能测试,以及回归测试。</li>
<li>性能测试:通过加载web应用程序和监视
你的服务器它帮助你找出瓶颈,给出详细的
绩效评估报告。</li>
<li>加载测试工具以暴露在粗略测试中不会出现的错误,
比如容量测试或者寿命测试。</li>
<li>压力测试工具来压倒web应用程序资源和测试
应用程序可恢复性。</li>
<li>通过编写任何web重复任务的脚本来编写web代理,比如检查
一个网站还活着。</li>
</ul>
<hr/>
<p><a href="http://tsung.erlang-projects.org/" rel="noreferrer"><strong>Tsung</strong></a>是一个开源的多协议分布式负载测试工具</p>
<blockquote>
<p>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. WebDAV, LDAP
and MySQL support have been added
recently (experimental).</p>
<p>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
...).</p>
</blockquote>
<hr/>
<p>如果您决定编写自己的工具,您可能需要使用Python的<a href="http://docs.python.org/library/multiprocessing.html" rel="noreferrer"><strong>multiprocessing module</strong></a>,因为它允许您使用多个内核。您还应该查看<a href="http://twistedmatrix.com/trac/wiki/Documentation" rel="noreferrer"><strong>Twisted</strong></a>,因为它可以让您在线程数量有限的情况下轻松处理多个套接字。这比为每个套接字生成一个新线程要好得多。</p>
<p>你和Amazon EC2一起工作,所以我建议你使用Tsung。你可以租用十几台多核服务器几个小时,然后用Tsung运行一些非常重的负载测试。在这种配置下它的伸缩性非常好。</p>
<p>至于带宽,通常不是问题,但这取决于应用程序。在执行负载测试时,必须密切监视所有资源。</p>