473,498 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multythreading app memory consumption

Hi folks.
I've just faced with very nasty memory consumption problem.
I have a multythreaded app with 150 threads which use the only and the
same function - through urllib2 it just gets the web page's html code
and assigns it to local variable. On the next turn the variable is
overritten with another page's code. At every moment the summary of
values of the variables containig code is not more than 15Mb (I've just
invented a tricky way to measure this). But during the first 30 minutes
all the system memory (512Mb) is consumed and 'MemoryError's is arising.
Why is it so and how can I limit the memory consumption in borders, say,
400Mb? Maybe there is a memory leak there?
Thnx

The test app code:
Q = Queue.Queue()
for i in rez: #rez length - 5000
Q.put(i)
def checker():
while True:
try:
url = Q.get()
except Queue.Empty:
break
try:
opener = urllib2.urlopen(url)
data = opener.read()
opener.close()
except:
sys.stderr.write('ERROR: %s\n' % traceback.format_exc())
try:
opener.close()
except:
pass
continue
print len(data)
for i in xrange(150):
new_thread = threading.Thread(target=checker)
new_thread.start()
Oct 22 '06 #1
7 1711
Dennis Lee Bieber wrote:
On Mon, 23 Oct 2006 03:31:28 +0400, Roman Petrichev <ti**@inbox.ru>
declaimed the following in comp.lang.python:
>Hi folks.
I've just faced with very nasty memory consumption problem.
I have a multythreaded app with 150 threads which use the only and the
same function - through urllib2 it just gets the web page's html code
and assigns it to local variable. On the next turn the variable is
overritten with another page's code. At every moment the summary of
values of the variables containig code is not more than 15Mb (I've just
invented a tricky way to measure this). But during the first 30 minutes
all the system memory (512Mb) is consumed and 'MemoryError's is arising.
Why is it so and how can I limit the memory consumption in borders, say,
400Mb? Maybe there is a memory leak there?
Thnx
How much stack space gets allocated for 150 threads?
Actually I don't know. How can I get to know this?
>Q = Queue.Queue()
for i in rez: #rez length - 5000

Can't be the "test code" as you don't show the imports or where
"rez" is defined.
Isn't it clear that "rez" is just a list of 5000 urls? I cannot place it
here, but believe me all of them are not big - "At every moment the
summary of values of the variables containig code is not more than 15Mb"

Regards

Oct 23 '06 #2
Roman Petrichev wrote:
try:
url = Q.get()
except Queue.Empty:
break
This code will never raise the Queue.Empty exception. Only a
non-blocking get does:

url = Q.get(block=False)

As mentioned before you should post working code if you expect people
to help.

i.

Oct 23 '06 #3
Roman Petrichev:
Dennis Lee Bieber wrote:
> How much stack space gets allocated for 150 threads?
Actually I don't know. How can I get to know this?
On Linux, each thread will often be allocated 10 megabytes of stack.
This can be viewed and altered with the ulimit command.

Neil
Oct 23 '06 #4
Roman Petrichev wrote:
Hi folks.
I've just faced with very nasty memory consumption problem.
I have a multythreaded app with 150 threads
[...]
>
The test app code:
Q = Queue.Queue()
for i in rez: #rez length - 5000
Q.put(i)
def checker():
while True:
try:
url = Q.get()
except Queue.Empty:
break
try:
opener = urllib2.urlopen(url)
data = opener.read()
opener.close()
except:
sys.stderr.write('ERROR: %s\n' % traceback.format_exc())
try:
opener.close()
except:
pass
continue
print len(data)
for i in xrange(150):
new_thread = threading.Thread(target=checker)
new_thread.start()
Don't know if this is the heart of your problem, but there's no
limit to how big "data" could be, after

data = opener.read()

Furthermore, you keep it until "data" gets over-written the next
time through the loop. You might try restructuring checker() to
make data local to one iteration, as in:

def checker():
while True:
onecheck()

def onecheck():
try:
url = Q.get()
except Queue.Empty:
break
try:
opener = urllib2.urlopen(url)
data = opener.read()
opener.close()
print len(data)
except:
sys.stderr.write('ERROR: %s\n' % traceback.format_exc())
try:
opener.close()
except:
pass
--
--Bryan
Oct 24 '06 #5
Dennis Lee Bieber wrote:
How much stack space gets allocated for 150 threads?
In Python 2.5, each thread will be allocated

thread.stack_size()

bytes of stack address space. Note that address space is
not physical memory, nor even virtual memory. On modern
operating systems, the memory gets allocated as needed,
and 150 threads is not be a problem.
--
--Bryan
Oct 24 '06 #6
Bryan Olson wrote:
In Python 2.5, each thread will be allocated

thread.stack_size()

bytes of stack address space. Note that address space is
not physical memory, nor even virtual memory. On modern
operating systems, the memory gets allocated as needed,
and 150 threads is not be a problem.
Just a note that [thread|threading].stack_size() returns 0 to indicate
the platform default, and that value will always be returned unless an
explicit value has previously been set.

The Posix thread platforms (those that support programmatic setting of
this parameter) have the best support for sanity checking the requested
size - the value gets checked when actually set, rather than when the
thread creation is attempted.

The platform default thread stack sizes I can recall are:
Windows: 1MB (though this may be affected by linker options)
Linux: 1MB or 8MB depending on threading library and/or distro
FreeBSD: 64kB

--
-------------------------------------------------------------------------
Andrew I MacIntyre "These thoughts are mine alone..."
E-mail: an*****@bullseye.apana.org.au (pref) | Snail: PO Box 370
an*****@pcug.org.au (alt) | Belconnen ACT 2616
Web: http://www.andymac.org/ | Australia
Oct 24 '06 #7
Thank you guys for your replies.
I've just realized that there was no memory leak and it was just my
mistake to think so. I've almost disappointed with my favorite
programming language before addressing the problem. Actually the app
consume as much memory as it should and I've just miscalculated.
Regards
Oct 24 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2322
by: Mike P | last post by:
I know everything about reference counting and making sure you don't have large objects lying around. I have also profiled my app with multiple tools. I know about the fact GC collects memory but...
6
1911
by: Andy | last post by:
Along with many others I've noticed the large amount of memory that can be taken up by the aspnet_wp.exe. I've found that I can better control and limit this memory consumption by including a...
10
1449
by: Marty | last post by:
Hi, Does anybody is experiencing a lot of RAM consumption when using many threads ? If yes, how can we reduce that level of used memory? Thanks tou! Marty
1
1346
by: anandav2001 | last post by:
Hello developers, I have created an executable(system tray application) in VS.net 2003 using VB.net. My app was taking 30 MB memory(since some web services call are there which happens for each...
8
8514
by: Adrian | last post by:
Hi I have a JS program that runs localy (under IE6 only) on a PC but it has a memory leak (probably the known MS one!) What applications are there that I could use to look at the memory usage of...
7
6910
by: Salvador | last post by:
Hi, I am using WMI to gather information about different computers (using win2K and win 2K3), checking common classes and also WMI load balance. My application runs every 1 minute and reports...
8
2813
by: Raja Gregory | last post by:
Hi All, I have developed a server application in C#. While running this application, it is not running more than 30 minutes due to memory leak. Could you tell me what will be the problem?
9
5186
by: Adam Right | last post by:
Hi, Anyone suffers from the high memory usage of C# in windows applications? Is there a solution for that problem? Thanks...
2
2269
by: Jonas Maurus | last post by:
Hello everybody, I'm pondering the following problem: I want to write a Python program that receives messages via SMTP and stores them in a dict or an array. For my purposes it would be...
1
6884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4904
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4586
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1416
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
651
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.