|
List Info
Thread: Comet + Cherrypy Tutorial using orbited
|
|
| Comet + Cherrypy Tutorial using orbited |

|
2007-06-11 19:47:39 |
|
Hello,
I have just finished a tutorial on writing comet applications for CherryPy3, though the basic concepts will work fine with CherryPy2 as well. Comet is simply sending asynchronous events from the server to the browser. It is used by Gmail's chat application, for instance.
The tutorial can be found here: http://brbx.com/orbited/tutorials/cherrychat.html
This tutorial is part of the orbited project which is a python daemon to make comet easy.
I would appreciate feedback on the tutorial. Any problems or thoughts are welcome.
Thanks,
Michael Carter
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group. To post to this group, send email to cherrypy-users googlegroups.com To unsubscribe from this group, send email to cherrypy-users-unsubscribe googlegroups.com For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en -~----------~----~----~----~------~----~------~--~---
|
| Re: Comet + Cherrypy Tutorial using
orbited |

|
2007-06-12 04:33:31 |
Hi there,
On 6/12/07, Michael Carter <cartermichael gmail.com> wrote:
> Hello,
>
> I have just finished a tutorial on writing comet
applications for CherryPy3,
> though the basic concepts will work fine with CherryPy2
as well. Comet is
> simply sending asynchronous events from the server to
the browser. It is
> used by Gmail's chat application, for instance.
>
> The tutorial can be found here:
> htt
p://brbx.com/orbited/tutorials/cherrychat.html
>
> This tutorial is part of the orbited project which is a
python daemon to
> make comet easy.
>
> I would appreciate feedback on the tutorial. Any
problems or thoughts are
> welcome.
Thank you Michael for a good tutorial. Straight to the
point.
The tutorial seems more of a CherryPy tutorial for people
that know
Orbit - and not vice versa though. For example:
"If you recall our orbit.cfg file for this
tutorial"
I didn't find any reference to the orbit.cfg file anywhere.
Also, if
you could add a short explanation of why you use the tuple
(user,
cherrypy session, "/ajax") as a key - and how that
key is used to
match outgoing events to connected users.
I'm also missing an explanation of who/what handles the
"/cherrychat"
location. Seems the iframe doesn't specify a different host
or a port
- so is CherryPy handling that URL and forwarding it somehow
to Orbit?
Or does the Orbit stuff run in the same process as
CherryPy?
Anyways, this looks an interesting project. It so happens
that I'm
just planning a project that will use comet heavily and I
was planning
to do it with Twisted alone. I'll certainly consider this an
option.
Some "I haven't rtfm" questions:
Does Orbit support two way message passing, i.e. can the web
browser
use it to pass events to the server? I know one can just use
XHRs, but
I'm just curious.
You use the iframe transport method, what other methods are
supported?
Does it have any special provisions for communicating with
Flash/Flex/Apollo apps?
When you send events via orbit.simple.Client.event(...) - is
it the
responsibility of the sender to list all the receivers of
the event?
Can I send events to all connected users without tracking
them myself?
thanks,
Arnar
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-users googlegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribe googlegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: Comet + Cherrypy Tutorial using
orbited |

|
2007-06-12 06:40:22 |
|
Hey arnar,
Thanks for the feedback. You caught some pretty glaring problems in the tutorial and I've since corrected them. I'll answer your questions step by step.
I didn't find any reference to the orbit.cfg file anywhere. Good catch here, the reference to orbit.cfg is missing. I put it in and i believe it will help answer some other questions of yours as well.
Also, if you could add a short explanation of why you use the tuple (user, cherrypy session, "/ajax") as a key - and how that key is used to
match outgoing events to connected users. Another good catch. /ajax is an error.. it should in fact be /cherrychat.
I'm also missing an explanation of who/what handles the "/cherrychat" location. The /cherrychat is part of the orbit key... something that would have made more sense without the /ajax error.
Seems the iframe doesn't specify a different host or a port - so is CherryPy handling that URL and forwarding it somehow to Orbit?
Or does the Orbit stuff run in the same process as CherryPy?
The orbited daemon runs in a separate process. The conclusion mentions that instead of dealing with cross-domain scripting issues, the cherrychat tutorial simply uses the orbited proxy to skirt the issue. This is also made more clear in the new
orbit.cfg explanation.
Does Orbit support two way message passing,
i.e. can the web browser use it to pass events to the server? I know one can just use XHRs, but I'm just curious.
The idea of orbit is to handle the server->browser events and to use XHR as the browser->server transport.
You use the iframe transport method, what other methods are supported? Does it have any special provisions for communicating with
Flash/Flex/Apollo apps? orbit ships with XHR and iframe transports. Its actually pretty straightforward to add a transport, and in fact flash/flex is pretty high on the priorty list. I'm not sure what the state of python/flex is, but I wouldn';t 'want to reinvent a library to parse flex stuff. Assuming that exists though, it would take about an hour to add and test flex as a transport.
When you send events via orbit.simple.Client.event(...) - is it the responsibility of the sender to list all the receivers of the event?
Can I send events to all connected users without tracking them myself? the orbited daemon plays a pretty simple role so that it can be distributed across multiple nodes that have no knowledge of each other. Therefore its the sender';s responsibility to keep track of the receivers. There is a bayeux implementation in the works that will run on top of the orbited daemon and do just that -- keep track of channel subscriptions for event publication. Alternatively you could use the already existing cometd project, though the documentation for cometd is complete nonexistent.
-Michael
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group. To post to this group, send email to cherrypy-users googlegroups.com To unsubscribe from this group, send email to cherrypy-users-unsubscribe googlegroups.com For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en -~----------~----~----~----~------~----~------~--~---
|
| Re: Comet + Cherrypy Tutorial using
orbited |

|
2007-06-12 07:04:23 |
Hi there,
On 6/12/07, Michael Carter <cartermichael gmail.com> wrote:
> > I didn't find any reference to the orbit.cfg file
anywhere.
>
> Good catch here, the reference to orbit.cfg is missing.
I put it in and i
> believe it will help answer some other questions of
yours as well.
Ah, yes. Those five lines made the pieces fit
> The orbited daemon runs in a separate process. The
conclusion mentions that
> instead of dealing with cross-domain scripting issues,
the cherrychat
> tutorial simply uses the orbited proxy to skirt the
issue. This is also made
> more clear in the new orbit.cfg explanation.
Yes, indeed.
> > You use the iframe transport method, what other
methods are supported?
> > Does it have any special provisions for
communicating with
> > Flash/Flex/Apollo apps?
>
> orbit ships with XHR and iframe transports. Its
actually pretty
> straightforward to add a transport, and in fact
flash/flex is pretty high on
> the priorty list. I'm not sure what the state of
python/flex is, but I
> wouldn't 'want to reinvent a library to parse flex
stuff. Assuming that
> exists though, it would take about an hour to add and
test flex as a
> transport.
There's flashtickle by Bob Ippolito (http://undefined.org/pyt
hon/) and
DjangoAMF (http://djangoamf.sourceforge.jp/index.php?DjangoAMF_en
).
The latter looks more complete as far as AMF goes. I had to
tweak it a
little bit to get AMF3 to work, that is being able to read
it's own
output. I haven't tried talking to a flash/flex app though.
However, Bob is with Mochi Media and Flash apps is their
business.
> > When you send events via
orbit.simple.Client.event(...) - is it the
> > responsibility of the sender to list all the
receivers of the event?
> > Can I send events to all connected users without
tracking them myself?
>
> the orbited daemon plays a pretty simple role so that
it can be distributed
> across multiple nodes that have no knowledge of each
other. Therefore its
> the sender's responsibility to keep track of the
receivers. There is a
> bayeux implementation in the works that will run on top
of the orbited
> daemon and do just that -- keep track of channel
subscriptions for event
> publication. Alternatively you could use the already
existing cometd
> project, though the documentation for cometd is
complete nonexistent.
What is the difference between orbited and cometd, i.e. what
does (or
will) orbited do that cometd doesn't?
Arnar
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-users googlegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribe googlegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: Comet + Cherrypy Tutorial using
orbited |

|
2007-06-12 07:17:28 |
|
There's flashtickle by Bob Ippolito (
http://undefined.org/python/) and DjangoAMF (http://djangoamf.sourceforge.jp/index.php?DjangoAMF_en).
The latter looks more complete as far as AMF goes. I had to tweak it a
little bit to get AMF3 to work, that is being able to read it's own output. I haven't tried talking to a flash/flex app though.
However, Bob is with Mochi Media and Flash apps is their business.
I'll take a look at these libraries. Other people have asked me the same questions about a flash/flex transport, so this is good to know.
What is the difference between orbited and cometd, i.e. what does (or will) orbited do that cometd doesn't? There is a big issue with cometd and its scaling, and they've admitted as much on their lists. Cometd has no clear plan to add multiple nodes, though there are some vague ideas about putting the java event queue JMS or some other such thing behind it. I'm not really a fan of that approach and more to the point its a long way off in realization. The real problem is that all of the comted nodes will have to share state in some fashion. Orbited on the other hand scales much the way memcached does. an array of orbited nodes are treated as hash buckets in a hash table such that each orbited user key hashes to a particular node. The nodes have no idea of each other and that lack of shared state makes it trivial to add additional nodes.
Of course, this comes at a price -- orbited is a bit lower level than cometd. In orbited, as you noted, you have to keep track of your recipients for each event wheras in cometd thats built into the bayeux protocol. And speaking of the bayeux protocol, there is already an implementation in the dojo javascript toolkit. As for orbited its still a matter of writing your own javascript for the application.
Another fundamental difference is that the cometd demos are all geared towards straight javascript development. They focus on sending events from javascript to javascript, whereas orbited is about also dispatching events that originate from outside sources, such as an irc server or a jabber server.
Because of this focus, there isn't a documented pattern of developing server-side apps with cometd/bayeux wheras orbited concentrates on this area. Therefore its easy to use cherrypy or twisted or really any framework to communicate via orbited. One of those server-side apps built on orbit could be a cometd/baeyux implementation, and as I mentioned before, thats in the works now though if you really want to use bayeux its better just to use the current twisted implementation.
Lastly, orbited is likely faster that cometd. Its based on pyevent/libevent which generally outperforms twisted.
-Michael
Arnar
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group. To post to this group, send email to cherrypy-users googlegroups.com To unsubscribe from this group, send email to cherrypy-users-unsubscribe googlegroups.com For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en -~----------~----~----~----~------~----~------~--~---
|
| Re: Comet + Cherrypy Tutorial using
orbited |

|
2007-06-17 05:19:02 |
|
what issues does a threaded approach raise?
On 6/12/07, Michael Carter < cartermichael gmail.com">cartermichael gmail.com> wrote:
Hello,
I have just finished a tutorial on writing comet applications for CherryPy3, though the basic concepts will work fine with CherryPy2 as well. Comet is simply sending asynchronous events from the server to the browser. It is used by Gmail's chat application, for instance.
The tutorial can be found here: http://brbx.com/orbited/tutorials/cherrychat.html
This tutorial is part of the orbited project which is a python daemon to make comet easy.
I would appreciate feedback on the tutorial. Any problems or thoughts are welcome.
Thanks,
Michael Carter
-- http://ionel.zapto.org ionel.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group. To post to this group, send email to cherrypy-users googlegroups.com To unsubscribe from this group, send email to cherrypy-users-unsubscribe googlegroups.com For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en -~----------~----~----~----~------~----~------~--~---
|
| Re: Comet + Cherrypy Tutorial using
orbited |

|
2007-06-17 07:11:28 |
Hi there,
On 6/17/07, Ionel Maries Cristian <ionel.mc gmail.com> wrote:
> what issues does a threaded approach raise?
Threads are by nature expensive. The memory useage of a
pthreads
thread is usually about 1-2 mb.
The premise of using threads for a webserver is that
requests are
handled fairly quickly each (measured in milliseconds). You
keep a
thread pool of several dozen threads (depending on your
load) and only
keep a reference to a thread for the duration of the
request
Comet uses long-running connections however. There can be
many seconds
and even minutes between the time the connection is made
until the
response is sent. In the meantime, a threaded server keeps a
thread
checked out for that duration without using it.
If you have on average 1000 connected users, this means you
need to
have 1000 threads just for the comet stuff - plus threads to
server
the regular requests. That's 1-2 GB of memory that goes
largely
unused.
Another factor is that context-switching between threads is
expensive.
Not as expensive as context switching processes - but you
need to
switch out the whole calling stack every time. Threads that
do little
or no work are thus inefficient because they only waste time
switching
back and forth.
Arnar
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-users googlegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribe googlegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: Comet + Cherrypy Tutorial using
orbited |
  United States |
2007-06-17 14:25:07 |
On Jun 17, 3:11 pm, "Arnar Birgisson"
<arna... gmail.com> wrote:
> Hi there,
>
> On 6/17/07, Ionel Maries Cristian <ionel... gmail.com> wrote:
>
> > what issues does a threaded approach raise?
>
> Threads are by nature expensive. The memory useage of a
pthreads
> thread is usually about 1-2 mb.
>
> The premise of using threads for a webserver is that
requests are
> handled fairly quickly each (measured in milliseconds).
You keep a
> thread pool of several dozen threads (depending on your
load) and only
> keep a reference to a thread for the duration of the
request
>
> Comet uses long-running connections however. There can
be many seconds
> and even minutes between the time the connection is
made until the
> response is sent. In the meantime, a threaded server
keeps a thread
> checked out for that duration without using it.
>
> If you have on average 1000 connected users, this means
you need to
> have 1000 threads just for the comet stuff - plus
threads to server
> the regular requests. That's 1-2 GB of memory that goes
largely
> unused.
>
> Another factor is that context-switching between
threads is expensive.
> Not as expensive as context switching processes - but
you need to
> switch out the whole calling stack every time. Threads
that do little
> or no work are thus inefficient because they only waste
time switching
> back and forth.
>
> Arnar
i wasn't referring to a threaded approach to the comet
communication,
but the cherrypy thread pool, sice you usualy have multiple
requests
comming at a given moment and 1 thread would give some
latency if that
1 cp thread isn't fast enough
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-users googlegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribe googlegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: Comet + Cherrypy Tutorial using
orbited |

|
2007-06-18 02:44:32 |
|
Hey Ionel,
i wasn't referring to a threaded approach to the comet communication,
but the cherrypy thread pool, sice you usualy have multiple requests comming at a given moment and 1 thread would give some latency if that 1 cp thread isn't fast enough
I assume then you're talking about the fact that in the tutorial I set the cherrypy threadpool to 0. I only did this because I wanted to keep the tutorial as simple as possible. Really, there is no reason not to keep open an orbited connection for every thread. It really depends on your application though.
In the case of the chat tutorial, the threads all need to share some state -- that is, they all need access to the list of connected users. As long as you use the python threading module to share that state and start up an orbited connection for each thread, everything will work fine.
-Michael
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group. To post to this group, send email to cherrypy-users googlegroups.com To unsubscribe from this group, send email to cherrypy-users-unsubscribe googlegroups.com For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en -~----------~----~----~----~------~----~------~--~---
|
[1-9]
|
|