473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to increase number of threads per process?

Hi,

I have created a python script (see below) to count the maximum number
of threads per process (by starting new threads continuously until it
breaks).

######
#testThread.py
import thread, sys

def main():
print "Main Thread:", thread.get_ident()
count = 0;
try:
while 1:
thread.start_new_thread(test,(`count`,))
count = count + 1;
except:
print "Total Threads:", count
print "Exiting Main Thread:", thread.get_ident()
raise

def test(input=None):
print "count:", thread.get_ident(), input
while 1: #keep thread alive until it breaks
pass

if __name__ == "__main__":
main()

#####

Results:

1. SuSE Professional 7.1 (Kernel 2.4.18), Python 1.5.2
Max Threads = 1024

2. SuSE Professional 7.1 (Kernel 2.4.18), Python 2.0
Max Threads = 1024

3. SuSE Enterprise Server 8.0 (Kernel 2.4.18), Python 1.5.2
Max Threads = 256

4. SuSE Enterprise Server 8.0 (Kernel 2.4.18), Python 2.2
Max Threads = 512

Note:
For all setup, SuSE Linux threads-max=14336 and max_map_count=65536

Questions:
1. How to determine the number of threads? Is it something
configurable?
2. Why do the results above differ in output?
3. How to increase the maximum number of threads per process?
Thanks and hope to hear soon.
Ronan
Jul 18 '05 #1
3 5368
Ronan,

Ronan Viernes wrote:
Hi,

I have created a python script (see below) to count the maximum number
of threads per process (by starting new threads continuously until it
breaks).

######
#testThread.py
import thread, sys

def main():
print "Main Thread:", thread.get_ident()
count = 0;
try:
while 1:
thread.start_new_thread(test,(`count`,))
count = count + 1;
except:
print "Total Threads:", count
print "Exiting Main Thread:", thread.get_ident()
raise

def test(input=None):
print "count:", thread.get_ident(), input
while 1: #keep thread alive until it breaks
pass

if __name__ == "__main__":
main()

#####

Results:

1. SuSE Professional 7.1 (Kernel 2.4.18), Python 1.5.2
Max Threads = 1024

2. SuSE Professional 7.1 (Kernel 2.4.18), Python 2.0
Max Threads = 1024

3. SuSE Enterprise Server 8.0 (Kernel 2.4.18), Python 1.5.2
Max Threads = 256

4. SuSE Enterprise Server 8.0 (Kernel 2.4.18), Python 2.2
Max Threads = 512

Note:
For all setup, SuSE Linux threads-max=14336 and max_map_count=65536

Questions:
1. How to determine the number of threads? Is it something
configurable?
2. Why do the results above differ in output?
3. How to increase the maximum number of threads per process?

I'm not sure if this is configurable but I was testing out something
similar today (on fedora core 1). I discovered that a structure such as
the following works with any number of thread (I tried it with 2000
threads just now). The main thing I did was introducing a
'time.sleep(0.01)' in the loop that waits for the worker threads to join
the main thread, and adding a try..except clause around where you start
the threads. Basically an exception is never thrown because I run 10
threads at one go, and then sleep for a fraction of a second (it's
usually a good idea to sleep/yield in busy loops). I think the main
thing here is the fact that it takes 10 threads at a time and then gives
it a pause.

Please try this out and let me know what you find.

class A:
cache = {}
counter = 0
def local(self):
A.cache[A.counter*2] = A.counter
A.counter += 1

def print_it(self):
print A.cache, len(A.cache), A.counter
def test():
count = 2000 # I'm pretty sure a larger number should work too

a = A()
threadList = []
for i in xrange(count):
try:
t = threading.Thread(target=a.local, args=())
threadList.append(t)
t.start()

# Adding the following if statement allowed running more
than 256 threads in one go
# Previously it would run only 256 threads if this clause
wasn't there.
if i % 10 == 0 and i != 0:
# setting sys.setcheckinterval to 1 didn't help. Let's try
# voluntarily giving up some cycles -- this should give
# other threads a chance to run
time.sleep(0.01) # this works with time.sleep(0.005)
as well
# end if
except:
continue
# end try
# end for

# Wait for threads to join the main thread
while threading.activeCount()>1:
time.sleep(1)

a.print_it()

test()


Thanks and hope to hear soon.
Ronan


Steve

Jul 18 '05 #2
Hi Steve,

Thanks for the info. Unfortunately, adding the sleep to my previous
example (modified version below) did not alter the results. Please
take note that I am using thread library (and not threading). The
sample code below is simplified version of our system and of course
each of the thread has other tasks to do rather than staying idle in
there.

What really puzzles me now is, if I change the environment (OS and
Python Versions) accordingly it will give different results. This made
me believe that it is somewhat 'configurable'.

Anyway, I really appreciate the help. Let's wait what the others have
to say.
######
#testThread.py
import thread, sys

def main():
print "Main Thread:", thread.get_ident()
count = 0;
try:
while 1:
thread.start_new_thread(test,(`count`,))
count = count + 1;
if count % 10 == 0 and count != 0:
time.sleep(0.01)
except:
print "Total Threads:", count
print "Exiting Main Thread:", thread.get_ident()
raise

def test(input=None):
print "count:", thread.get_ident(), input
while 1: #keep thread alive until it breaks
pass

if __name__ == "__main__":
main()

#####

Results:

1. SuSE Professional 7.1 (Kernel 2.4.18), Python 1.5.2
Max Threads = 1024

2. SuSE Professional 7.1 (Kernel 2.4.18), Python 2.0
Max Threads = 1024

3. SuSE Enterprise Server 8.0 (Kernel 2.4.18), Python 1.5.2
Max Threads = 256

4. SuSE Enterprise Server 8.0 (Kernel 2.4.18), Python 2.2
Max Threads = 512

Note:
For all setup, SuSE Linux threads-max=14336 and max_map_count=65536

Questions:
1. How to determine the number of threads? Is it something
configurable?
2. Why do the results above differ in output?
3. How to increase the maximum number of threads per process?


Regards,
Ronan
Jul 18 '05 #3
On 13 Jul 2004 19:27:21 -0700, Ronan Viernes <ro***********@onsemi.com> wrote:
Hi Steve,

Thanks for the info. Unfortunately, adding the sleep to my previous
example (modified version below) did not alter the results. Please
take note that I am using thread library (and not threading). The
sample code below is simplified version of our system and of course
each of the thread has other tasks to do rather than staying idle in
there.

What really puzzles me now is, if I change the environment (OS and
Python Versions) accordingly it will give different results. This made
me believe that it is somewhat 'configurable'.


as far as I know, it's the way your glibc is compiled that makes the difference.

--
John Lenton (jl*****@gmail.com) -- Random fortune:
bash: fortune: command not found
Jul 18 '05 #4

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

Similar topics

31
by: AlexeiOst | last post by:
Everywhere in documentation there are recommendations to use threads from thread pooling for relatively short tasks. As I understand, fetching a page or multiple pages (sometimes up to 50 but not...
2
by: Do Park via SQLMonster.com | last post by:
Hello all, A software that connects SQL Server via ODBC uses 12 process at the same time when I look at the process info(panel). Is it possible to increase number of process (or thread) for a...
0
by: Sam Hale | last post by:
Hi, thanks for any help in advanced. I'm trying to create a simple (or atleast what seems simple) form using ASP VB. It will appear at the bottom of an article, and act much like a rating...
2
by: Smriti Dev | last post by:
Hi, I wanted to find out how I can create a query that will increase the count by 1. I have a mysql table linked to an access table. However, I loose the autonumber key when I link the tables,...
2
by: DraguVaso | last post by:
Hi, I need to do osme handlings with an Internet Explorer Window. The problem is: when the user has one ore more Internet Explorers opened, this is (sometimes) indicated in the Task Manager as...
3
by: Edwin New | last post by:
I need to increase the number of connections to PostgreSQL 7.2.1. I have tried changing the value of max_connections in Postgresql.conf. It was commented out (as are all other entries except...
5
by: HowHow | last post by:
I am using Access 2000. I have few tables with primary keys, for example, StaffID, OrgID, CourseID and BookingID. In order for me to recognize my IDs easily later, I want to set a fixed character in...
4
by: Marcus Alves Grando | last post by:
Hello list, I have a strange problem with os.walk and threads in python script. I have one script that create some threads and consume Queue. For every value in Queue this script run os.walk()...
3
by: tshad | last post by:
I need to find out how many threads a process has. I have used ThreadPool.GetAvailableThreads and ThreadPool.GetMaxThreads, but they both show 50 for worker threads and 100 for port threads. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.