Hello,
I'm getting my feet wet in Python and thought I'd try to see how well
Python works for asynchronous messaging. I've been using asynchronous
messaging for 5 years and find it advantageous for many things. In the
scheme I use communication is not only asynchronous but it is also non-
blocking and inherently serialized via a queue.
This provides two benefits, a sender is never directly effected by the
receiver and since the receiver handles only one message at a time
it generally never has to use mutexes or semaphores. This allows for
the
programmer to use multiple threads without having to contend with the
associated issues mutexes have in the area of deadly embraces or race
conditions.
Anyway, below is a link to the first pass at an implementation
in Python, comments are welcome: http://www.saville.com/python/mproc.tgz
Regards,
Wink Saville 5 2005
wink wrote:
This provides two benefits, a sender is never directly effected by the
receiver and since the receiver handles only one message at a time
it generally never has to use mutexes or semaphores. This allows for
the programmer to use multiple threads without having to contend with the
associated issues mutexes have in the area of deadly embraces or race
conditions.
import Queue # ?
</F>
On 2007-09-26, wink <wi**@saville.c omwrote:
Hello,
I'm getting my feet wet in Python and thought I'd try to see how well
Python works for asynchronous messaging. I've been using asynchronous
Have a look at Twisted ( www.twistedmatrix.com)
Albert
wink wrote:
But its performance is poor if the number of items on a
Queue becomes large because it is implemented using a list.
One of the things I was thinking of was doing another implementation
using of Queue which was based on deque.
Updating from 2.3 to something newer will fix that, of course:
$ more Queue.py
....
from collections import deque
....
class Queue:
...
def _init(self, maxsize):
self.maxsize = maxsize
self.queue = deque()
</F>
Fredrik,
You are most correct, but Queue is slow compared to deque but
not for the reason I guessed. Apparently it's because deque is
implemented in C while Queue is in python. Using the program below
it looks there is about a 35:1 speed difference.
100 d.append 0.000011s 0.1097us per
100 d.popL 0.000011s 0.1097us per
100 q.put 0.000429s 4.2892us per
100 q.get 0.000391s 3.9077us per
So someday it _might_ warrant adding Queue to collections.
#!/usr/bin/python
import timeit
import Queue
from collections import deque
setupD = """
from collections import deque
d=deque()
cnt = %d
for x in xrange(cnt):
d.append(x)
"""
setupQ = """
import Queue
q=Queue.Queue()
cnt = %d
for x in xrange(cnt):
q.put(x)
"""
def main():
cnt = 100
t = timeit.Timer(se tup=setupD % cnt, stmt="d.append( 0)")
time = min(t.repeat(10 000, cnt))
print " %9d d.append %fs %7.4fus per" % \
(cnt, time, (time/cnt) * 1000000.0)
t = timeit.Timer(se tup=setupD % cnt, stmt="d.popleft ()")
time = min(t.repeat(10 000, cnt))
print " %9d d.popL %fs %7.4fus per" % \
(cnt, time, (time/cnt) * 1000000.0)
t = timeit.Timer(se tup=setupQ % cnt, stmt="q.put(0)" )
time = min(t.repeat(10 000, cnt))
print " %9d q.put %fs %7.4fus per" % \
(cnt, time, (time/cnt) * 1000000.0)
t = timeit.Timer(se tup=setupQ % cnt, stmt="q.get()")
time = min(t.repeat(10 000, cnt))
print " %9d q.get %fs %7.4fus per" % \
(cnt, time, (time/cnt) * 1000000.0)
if __name__ == "__main__":
main()
En Thu, 27 Sep 2007 01:43:32 -0300, wink <wi**@saville.c omescribi�:
You are most correct, but Queue is slow compared to deque but
not for the reason I guessed. Apparently it's because deque is
implemented in C while Queue is in python. Using the program below
it looks there is about a 35:1 speed difference.
That't not the reason. A Queue is built around a container, and it happens
to be a deque in the default implementation. But the important thing is
that a Queue is a synchronized object - it performs the necesary
synchronization to ensure proper operation even from multiple threads
attempting to use it at the same time.
So your comparison is meaningless, apart from telling that using mutexes
is not cheap.
--
Gabriel Genellina This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dennis Owens |
last post by:
I want to develop a Client/Server messaging system that
does not require Microsoft messaging. I want to use
the .Net remoting, but I am having some real problems with
the remoting. The remoting really seems to be a one way
street in terms of messaging. Ex.( The Client can
communicate with the server and get information back from
the server, but the server cannot make a call to the
client unless you set up another remoting session were the...
|
by: Dennis Owens |
last post by:
Read below for previous conversation.
We are developing an application that will some day run on
anything from a computer down to a PDA (this is were the
Lightweight comes in). The messaging that we want to send
will be very straightforward. If one of the clients has
changed some data, the other clients need to know about
it. If the clients are not on line then the message may
have to wait until they are on line. The messages
|
by: ptdaw |
last post by:
After spending a little time reading the documentation, I attempted to add
some messaging code to my VB.Net project, only to discover that I couldn't
get past my
Imports System.Messaging
statment because the System.Messaging namespace is missing. Did I fat
finger it into oblivion without knowing it, or is this a known issue? Any
suggestions on how to fix this, in any case?
|
by: Michael C |
last post by:
Hi all,
Is there an easy way to get the parameters of an asynchronous delegate call
from the callback function? Here's an example of what I'm trying to do:
private delegate ArrayList AsyncDelegate (string server);
private void GetServerInfo (string server)
{
AsyncDelegate ad = new AsyncDelegate(GetServerArray);
|
by: John A Grandy |
last post by:
in .NET 2.0 where is the type Message located ?
in .NET 1.1 it was System.Messaging.Message
| |
by: Sharon |
last post by:
I have a remoting object, lets call it A, that fires an event to remotely
registered handlers, lets call it B.
The invocation is working OK and the remote handler B is handling the event
like it should.
But I need A to catch any exception thrown from the handler B, and also I
need that A will get the returned value returned by handler B.
For that I wrote:
private void ResultsHandler(IAsyncResult ar)
|
by: John Grant |
last post by:
If I build a web services today with VS 2005 does it support reliable
messaging?
If I use WSE 3.0 will it support reliable messaging?
If I don’t have reliable messaging can I make a web method call that does
not reach the web service?
If so, what does the call do? Timeout, hang?
thanks
|
by: =?Utf-8?B?aGVyYmVydA==?= |
last post by:
I need to build an event-based asynchronous pattern (around a send/receive
messaging API).
Is there a step-by-step guidance about how to write code for the EBAP ?
Does any book cover this theme (VB.NET preferred)?
thanks herbert
|
by: jparulan |
last post by:
Hi All,
I am developing web service that does not use IIS, I was successful on deploying a normal web service with System.Data and System.Web namespaces. BUT when I added the System.Messaging and deploy my windows service - I am getting this error while accessing the ASMX test form
* I have tried the following already.
1. Remove and Add the System.Messaging from "Reference"
2. System.Messaging does exist from the GAC.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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 we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |