[Twisted-Python] How to dispatch message to different servers

Glyph glyph at twistedmatrix.com
Sat Mar 2 14:58:58 EST 2013

On Mar 2, 2013, at 5:46 AM, Phil Mayers <p.mayers at imperial.ac.uk> wrote:

> You seemed curious why someone wouldn't use AMP. Personally I have two 
> common use-cases:
>  1. Communicating between two trusted Twisted processes, for which PB 
> is good enough.

There are two reasons that someone might want to consider AMP in this case.  I am not necessarily saying you would want to consider AMP here - you seem to be pretty happy with your decision and I'm not saying it's wrong.  I even gave some reasons why PB would be a better idea sometimes.

One is that it makes it a bit easier to replace one end of the wire with something that isn't Twisted - or at least, preserve the plausible deniability that you might, which can make it more politically palatable to deploy Twisted in the first place :).  Granted, "use PyPy" is increasingly a better argument for the sorts of people who would want this assurance - performance nuts - than "you could re-implement in another language later".  Still, if there are other reasons, or you are in an environment where another language is popular, while PB implementations for other languages do exist, and I have deployed polyglot PB clusters, it adds a surprising dimension of additional complexity.  Deploying a polyglot AMP system is a breeze, even if you have to implement AMP from scratch for the other language in order to do it ;).

Another reason is that it makes versioning the protocol easier.  With PB, it's very easy to build a protocol that mirrors your application's internal state, and expose implementation details accidentally, which then have to be painstakingly emulated when you roll out a new version.  This isn't much of a concern if your protocol is pretty stable, and/or your application upgrades are synchronized.

Like you said though: writing up all those message format declarations is not zero-cost.  It's certainly much quicker to get a basic PB cluster up and running since you can just toss a couple of remote_ declarations in and be off to the races.

There is a good reason Twisted still ships both and we have no plans to ever get rid of PB :).

>  2. Communicating with a semi-trusted third party process, for which a 
> RESTful interface or XML/JSON RPCs are *available* and sufficiently 
> secure and capable for my needs.

For this one, obviously, XML or JSON-RPC is the right choice.  I mean, heck, 90% of Twisted is implementations of messy, arguably bad protocols (IMAP?  POP?  **FTP?**) which you probably shouldn't use, except you have to because you want to talk to a system that uses them :).

> Obviously other people will have radically different needs, but for me, 
> AMP adds little.

Sure.  It might not be for everybody.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20130302/c44b3f47/attachment.htm 

More information about the Twisted-Python mailing list