On Thu, 2003-04-17 at 14:57, Mike Orr wrote:
> I haven't looked at this yet, but I'm interested in seeing how Webware
> and Twisted can integrate. Ian's approach (porting the AppServer to
> Twisted) is one way. Another way would be to make a Twisted Web
> adapter to a standalone AppServer. That would probably be the
> easiest, and then you could run T. Web rather than Apache.
Making an adapter would be quite easy, perhaps to the point that it
would be slightly boring ;) But you'd get a chance to try Twisted
programming, since Adapter would have to be rewritten with this in
mind... so probably not boring.
> A third way would be to port the servlet API to Twisted, perhaps
> using a Resource subsclass. That could either be the full API
> or possibly one that dispenses with unneded features (for instance,
> don't parse GET/POST variables if the servlet won't use them).
> Thus, it may be possible to use Webware servlets unmodified using
> a compatibility wrapper.
If this became more than an experiment, this would start to happen
gradually, as eventually the duplicate code is removed. I think this
would reveal Webware's underlying simplicity, which is lost amid all the
> One major problem is the single-threaded nature of Twisted compared
> to multi-threaded Webware. That requires significant thinking to
> avoid freezing the other Twisted connections. For instance, you have
> to use a special API for database access, and I'm not sure how well
> MySQL is supported (I saw only Posgres mentioned in specifically).
> Any other operation that takes a "long time", perhaps because it
> waits for a server response (e.g., the AppServer). You can run
> the Webware portion under a separate thread(s), but that nullifies
> the performance gain that is one of Twisted's selling points. On the
> other hand, performance would prob'ly be no *worse* than Apache or
> standalone Webware, so maybe you haven't really lost anything.
I implemented this in separate threads, which is what everyone writing
Webware servlets expects. You have to be quite careful to write proper
async code, and it certainly doesn't just happen naturally. I don't
think async will become popular as a programming methodology, the gains
aren't significant enough -- performance isn't that big a deal, and
people are becoming used to thread programming so I'm not convinced by
arguments that you have less concurrency problems with async.
Woven (a more experimental framework built on Twisted) does embrace
async, but the result is rather odd. I guess there's lots of ways to
think about it, but I'd say it makes you phrase your application as a
series of callbacks, which it calls as necessary. Things like data
sources or other normally blocking code is part of the framework.
> It sounds like Ian has already started the analysis of how much of
> Twisted's URL parsing and "extra path info" code can substitute
> for Webware's. Perhaps also things like sessions and user managers
> would want to be rethought in light of of the services Twisted
I'm not sold on the Twisted style of programming, but I'm mostly
thinking about how Webware can fit into a larger Python universe, and
Twisted may be part of that.
> I would like, experimentally, to code a mostly-Webware-compatible
> servlet handler that makes full use of Twisted's services and
> single threading, but first I have a YAML version to write, and
> finish the Webware architectural overview I started during PyCon,