473,408 Members | 2,417 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,408 software developers and data experts.

To thread or not to thread

Hello,
I was recently reading an article on threading in python and I
came across Global Interpreter Lock,now as a novince in python I was
cusrious about

1.Is writing a threaded code in python going to perform well than a
normal python code.If so on what basis can it performance be measured.

2.Is writing a threaded code in python better than a code written in
C/C++ using PTHREADS.

If someone can comment on these questions, it would be great.

Jul 28 '05 #1
4 1156
On 2005-07-28, Sidd <ia*****@gmail.com> wrote:
I was recently reading an article on threading in python and I
came across Global Interpreter Lock,now as a novince in python
I was cusrious about

1.Is writing a threaded code in python going to perform well
than a normal python code.
It's sort of a corrolary to Amdahls law: on a single CPU
machine, optimally written multi-threaded code will always
perform worse than optimally written single-threaded code.
[Where performance is in terms of CPU efficiency.]

However, it may be very difficult to write optimal
single-threaded code, and much easier to write (nearly) optimal
multi-threaded code. So, in practice, multi-threaded code
often performs better for certain classes of problems.
If so on what basis can it performance be measured.
That's up to whoever is doing the measuring.
2.Is writing a threaded code in python better than a code
written in C/C++ using PTHREADS.


Define "better".

On a multi-CPU machine you can get much more parallelism for
compute-intensive tasks using C/pthreads than you can using
Python threads.

It's also a lot easier to write buggy code containing race
conditions using C/pthreads.

--
Grant Edwards grante Yow! I want to read my new
at poem about pork brains and
visi.com outer space...
Jul 28 '05 #2
Some people are of the opinion that threads are evil.....

Best Regards,

Fuzzy
http://www.voidspace.org.uk/python

Jul 29 '05 #3
On 2005-07-28, Sidd <ia*****@gmail.com> wrote:
Hello,
I was recently reading an article on threading in python and I
came across Global Interpreter Lock,now as a novince in python I was
cusrious about

1.Is writing a threaded code in python going to perform well than a
normal python code.If so on what basis can it performance be measured.
My last "real" experience with python threads was a while back, on a P-2.
That experience suggested that creating "lots" of threads (a few hundred)
caused some serious performance impacts. I determined, in that instance,
that it was better to write my own implementation to simulate threads.
I had set of classes that pretended to be threads. I had another class
which actually did all the threading for them. It was pretty ugly.
2.Is writing a threaded code in python better than a code written in
C/C++ using PTHREADS.
I agree with the earlier. Define "better." Do you really have a heavily
multi-threaded app? Are these threads all CPU-intensive, or do you just
have a bunch of threads which need some arbitrary scheduling? Is it really
worth re-writing in PTHREADS? Or could you buy a new server and save a few
months in development time by writing your own scheduling?

It all depends on your situation.

If someone can comment on these questions, it would be great.


Heh. You're on Usenet. *Anyone* can comment on these questions. :-)
You should have asked for *useful* comments. ;-)
--
Liberty means responsibility. That is why most men dread it.
- George Bernard Shaw

Jul 30 '05 #4
On 28 Jul 2005 12:10:12 -0700, Sidd <ia*****@gmail.com> wrote:
Hello,
I was recently reading an article on threading in python and I
came across Global Interpreter Lock,now as a novince in python I was
cusrious about

1.Is writing a threaded code in python going to perform well than a
normal python code.If so on what basis can it performance be measured.

2.Is writing a threaded code in python better than a code written in
C/C++ using PTHREADS.

If someone can comment on these questions, it would be great.


If you want performance with an application that does a lot of
concurrent activity, you might take a look at
http://www.twistedmatrix.com which is an event driven framework for
python.
Much better performance than threads with a lot less memory and cpu
usage. Although it does have a bit of a learning curve. In my own
experience it would be faster then a comparable application written
in C using pthreads. We have an application written in twisted that
processes financial applications via bank networks, and at a steady
100tps I get about 1% cpu usage. We tested it up to around 1000tps
before our database server started to get a bit overloaded. Twisted
never used more than 20% of the cpu though.

Chris
Jul 30 '05 #5

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

Similar topics

14
by: adeger | last post by:
Having trouble with my first forays into threads. Basically, the threads don't seem to be working in parallel (or you might say are blocking). I've boiled my problems to the following short code...
4
by: Gilles Leblanc | last post by:
Hi I have started a small project with PyOpenGL. I am wondering what are the options for a GUI. So far I checked PyUI but it has some problems with 3d rendering outside the Windows platform. I...
7
by: Ivan | last post by:
Hi I have following problem: I'm creating two threads who are performing some tasks. When one thread finished I would like to restart her again (e.g. new job). Following example demonstrates...
4
by: Matthew Groch | last post by:
Hi all, I've got a server that handles a relatively high number of concurrent transactions (on the magnitude of 1000's per second). Client applications establish socket connections with the...
5
by: Razzie | last post by:
Hi all, A question from someone on a website got me thinking about this, and I wondered if anyone could explain this. A System.Threading.Timer object is garbage collected if it has no...
16
by: droopytoon | last post by:
Hi, I start a new thread (previous one was "thread timing") because I have isolated my problem. It has nothing to do with calling unmanaged C++ code (I removed it in a test application). I...
9
by: mareal | last post by:
I have noticed how the thread I created just stops running. I have added several exceptions to the thread System.Threading.SynchronizationLockException System.Threading.ThreadAbortException...
13
by: Bob Day | last post by:
Using vs2003, vb.net I start a thread, giving it a name before start. Code snippet: 'give each thread a unique name (for later identification) Trunk_Thread.Name = "Trunk_0_Thread" ' allow...
7
by: Charles Law | last post by:
My first thought was to call WorkerThread.Suspend but the help cautions against this (for good reason) because the caller has no control over where the thread actually stops, and it might have...
3
by: John Nagle | last post by:
There's no way to set thread priorities within Python, is there? We have some threads that go compute-bound, and would like to reduce their priority slightly so the other operations, like...
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: 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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...
0
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...

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.