[Tutor] Threads very simple examle

Oleg Oltar oltarasenko at gmail.com
Thu Sep 10 12:21:04 CEST 2009


On Thu, Sep 10, 2009 at 12:43 PM, Alan Gauld <alan.gauld at btinternet.com>wrote:

> "Oleg Oltar" <oltarasenko at gmail.com> wrote
>
>  I want to create simple load test for my web application.
>> Consider the following script:
>>
>> while 1:
>>   urllib2.urlopen("www.example.com")
>>
>
> Just a small caveat.
> If you try a load test like this from a single PC you might get very
> surprising (and non representative) results. Remember that each request will
> be sharing a single network connection, so the performance bottleneck
> can very quickly become the network interface not the server. It depends of
> course on what you are measuring and how many threads you want to run. Just
> be aware of the full architecture that you are testing to make sure what you
> measure is what you mean to measure.
>
> Load testing is a very complex task, frought with potential
> for false results. I've seen far more erroneous load tests than I've seen
> valid ones!If you on;y want to test for 3 or 4 connections then it is
> probably OK but if you try running dozens of concurrent tests it will almost
> certainly fail to reflect reality. The same applies to the server of course,
> if it only has one network connection then it may bottleneck there too. But
> most servers (in a data center environment) have at least two network
> interfaces running so its usually  less of an issue.
>
>  How can I make it running in several threads?
>>
>
> I'll leave the threading part to someone else.
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


Yes, I use tsung to make massive tests, but I just wanted to make some small
test runner for approx 10-20 threads

Here what I've done:


import
urllib2

from threading import
Thread





def
btl_test():

    while
True:

        page = urllib2.urlopen("example.com")
        print
page.code



for i in
range(120):

    t = Thread(target =
btl_test)


t.start()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090910/24274578/attachment.htm>


More information about the Tutor mailing list