Austine Jane | 3 Nov 2004 11:55
Picon
Favicon

Using Twisted-web with Nevow for high-traffic site

Hello

We are going to build a web application and want to know if twisted+nevow 
fit our situation. Our server has four cpus running. Our web application 
would require high cpu load sometimes, and a multiple of users might use the 
system at the same time.

I guess twisted is single threaded server model. How could we make it scale 
well and make advantage of four cpus? Does it support process farm like scgi 
server?

Thanks.

Jane

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! 
http://messenger.msn.com/
Tommi Virtanen | 4 Nov 2004 08:47

Re: Using Twisted-web with Nevow for high-traffic site

Austine Jane wrote:

>  We are going to build a web application and want to know if
>  twisted+nevow fit our situation. Our server has four cpus running.
>  Our web application would require high cpu load sometimes, and a
>  multiple of users might use the system at the same time.
>
>  I guess twisted is single threaded server model. How could we make it
>  scale well and make advantage of four cpus? Does it support process
>  farm like scgi server?

Have a frontend service that load balances connections to four or maybe
five instances of Twisted. For example LVS, iptables NAT rules, apache
or Twisted itself can be used as the load balancer, depending on your
needs.

In essence, treat your 4 CPUs like you would treat 4 separate machines.
Peter Hunt | 4 Nov 2004 19:35
Picon

Buffered requests

I'm wondering if there is a way that I can "buffer" a request, store
the output it would normally send to the client in a string, and then
output something different, such as a redirect, to the client.

For example, it'd be nice if it worked like this:

buffered_request.setHeader("Content-type","text/html")
buffered_request.write("<html>Hello %s</html>" %
buffered_request.args.get("name",["world"])[0])
buffered_request.finish()
output = buffered_request.getOutput()
request.setHeader("Content-type","text/plain")
request.write("The output that will be written to the client is:\n " + output)

The end result (in the browser) should be:

The output that will be written to the client is:
200 OK
Content-type: text/plain

<html>Hello world</html>

I've tried playing around with something called "queued", but I'm not
sure if that's what I want. Essentially I just want to capture the
output of a request in a string.

Thanks in advance.
Donovan Preston | 4 Nov 2004 22:02

Re: Buffered requests


On Nov 4, 2004, at 10:35 AM, Peter Hunt wrote:

> I'm wondering if there is a way that I can "buffer" a request, store
> the output it would normally send to the client in a string, and then
> output something different, such as a redirect, to the client.
>
> For example, it'd be nice if it worked like this:
>
> buffered_request.setHeader("Content-type","text/html")
> buffered_request.write("<html>Hello %s</html>" %
> buffered_request.args.get("name",["world"])[0])
> buffered_request.finish()
> output = buffered_request.getOutput()
> request.setHeader("Content-type","text/plain")
> request.write("The output that will be written to the client is:\n " + 
> output)
>
> The end result (in the browser) should be:
>
> The output that will be written to the client is:
> 200 OK
> Content-type: text/plain
>
> <html>Hello world</html>
>
> I've tried playing around with something called "queued", but I'm not
> sure if that's what I want. Essentially I just want to capture the
> output of a request in a string.

(Continue reading)

Erik Swan | 4 Nov 2004 22:33

Nested Nevow templates

Everyone,

I'm somewhat new to Nevow and have a simple question - btw, it maybe 
already possible and i missed the man page...

We mostly use HTML based templates to drive our presentations as we have 
an html designer that can design and maintain a large majority of the UI 
without knowledge of any coding.  The designer delivers html that can be 
rendered on its own for review but also adds in directives, patterns and 
slots to make the programmers life easier.

My question centers around the best way to have nested templates - that 
is i'd like a directive that would function as an include and all the 
appropriate Nevow render code get executed automatically. That way our 
designer can build a header, footer, sidebars, and other html components 
as separate files and the main template just "includes" as appropriate.  
Something like
  <nevow:include name="blah.html">

Additionally, and here is my Nevow ignorance, there must be a simple few 
lines of code that does the equivalent in code for example if i had:
  <nevow:render name = templateName>

then in...
  def render_templateName(self, context, data):
      #load and render file templateName as include and return result

Lastly, if the above method works OK then I'd rather have
  <nevow:render name=include nevow:arg=templateName>
where i can have a generic include render method and take an argument 
(Continue reading)

Peter Hunt | 4 Nov 2004 22:27
Picon

Re: Buffered requests

Will that include the HTTP response code and headers?

On Thu, 4 Nov 2004 13:02:14 -0800, Donovan Preston <dp <at> ulaluma.com> wrote:
> 
> 
> 
> On Nov 4, 2004, at 10:35 AM, Peter Hunt wrote:
> 
> > I'm wondering if there is a way that I can "buffer" a request, store
> > the output it would normally send to the client in a string, and then
> > output something different, such as a redirect, to the client.
> >
> > For example, it'd be nice if it worked like this:
> >
> > buffered_request.setHeader("Content-type","text/html")
> > buffered_request.write("<html>Hello %s</html>" %
> > buffered_request.args.get("name",["world"])[0])
> > buffered_request.finish()
> > output = buffered_request.getOutput()
> > request.setHeader("Content-type","text/plain")
> > request.write("The output that will be written to the client is:\n " +
> > output)
> >
> > The end result (in the browser) should be:
> >
> > The output that will be written to the client is:
> > 200 OK
> > Content-type: text/plain
> >
> > <html>Hello world</html>
(Continue reading)

orbitz | 4 Nov 2004 23:09

Re: Nested Nevow templates

Render methods can return rend.Page's. so

def render_nested(self, context, data):
    return Mypage()

If you want to pass data then just do
<nevow:data="whatever" nevow:render="nested"/>

Then define data_whatever to put some data on the stack and 
render_whatever to take the data and pass it ot yoru page constructor

Erik Swan wrote:

> Everyone,
>
> I'm somewhat new to Nevow and have a simple question - btw, it maybe 
> already possible and i missed the man page...
>
> We mostly use HTML based templates to drive our presentations as we 
> have an html designer that can design and maintain a large majority of 
> the UI without knowledge of any coding.  The designer delivers html 
> that can be rendered on its own for review but also adds in 
> directives, patterns and slots to make the programmers life easier.
>
> My question centers around the best way to have nested templates - 
> that is i'd like a directive that would function as an include and all 
> the appropriate Nevow render code get executed automatically. That way 
> our designer can build a header, footer, sidebars, and other html 
> components as separate files and the main template just "includes" as 
> appropriate.  Something like
(Continue reading)

Valentino Volonghi | 4 Nov 2004 23:17
Picon
Gravatar

Re: Nested Nevow templates

On Thu, 04 Nov 2004 13:33:10 -0800, Erik Swan <erik <at> splunktechnology.com> wrote:
> Everyone,
> 
> I'm somewhat new to Nevow and have a simple question - btw, it maybe
> already possible and i missed the man page...

Actually... Even a poor man page would be welcome these days :)

> My question centers around the best way to have nested templates - that
> is i'd like a directive that would function as an include and all the
> appropriate Nevow render code get executed automatically. That way our
> designer can build a header, footer, sidebars, and other html components
> as separate files and the main template just "includes" as appropriate.
> Something like
>   <nevow:include name="blah.html">

Nevow provides Fragments that are mostly like Page objects but could
be rendered inside another Page like they were simple tags or strings
(that fill slots).

<nevow:invisible nevow:render="content">
    <nevow:slot name="content" />
</nevow:invisible>

And in the code side:

    def render_content(self, ctx, data):
        ctx.tag.fillSlots('content', MyFragment())
        return ctx.tag

(Continue reading)

Matt Goodall | 4 Nov 2004 23:28

Re: Nested Nevow templates

On Thu, 2004-11-04 at 13:33 -0800, Erik Swan wrote:
> Everyone,
> 
> I'm somewhat new to Nevow and have a simple question - btw, it maybe 
> already possible and i missed the man page...
> 
> We mostly use HTML based templates to drive our presentations as we have 
> an html designer that can design and maintain a large majority of the UI 
> without knowledge of any coding.  The designer delivers html that can be 
> rendered on its own for review but also adds in directives, patterns and 
> slots to make the programmers life easier.
> 
> My question centers around the best way to have nested templates - that 
> is i'd like a directive that would function as an include and all the 
> appropriate Nevow render code get executed automatically. That way our 
> designer can build a header, footer, sidebars, and other html components 
> as separate files and the main template just "includes" as appropriate.  
> Something like
>   <nevow:include name="blah.html">

WARNING: Experimental code alert. Use at your own risk. ;-)

This sounds like you want macros. There is a relatively simple
implementation in my sandbox ...

    svn co svn://divmod.org/svn/Nevow/sandbox/mg/macro

The basic idea is that you have one (or more) XHTML files containing the
macros. The page templates include a macro by adding a n:render="macro
myMacro" attribute to some element.
(Continue reading)

Matt Goodall | 4 Nov 2004 23:47

Re: Nevow: Authenticated site with "remember me" and vhosts

On Sat, 2004-10-30 at 12:26 -0400, Donovan Preston wrote:
> On Oct 30, 2004, at 11:03 AM, Paul Moore wrote:
[...]
> > 2. I'd like to add a "remember me" checkbox, which if checked sets a
> >    cookie to remember the user's ID, so that they don't have to log
> >    in again for (say) 2 weeks. Much like gmail, or Yahoo, do. But I'm
> >    not too sure how I'd go about this. I'm not even sure where I'd
> >    *put* auto-login code: the page is too late (the guard has done
> >    its thing by then) but anything else seems to be too early (ie,
> >    not per-session, if you see what I mean). I suspect I need to
> >    subclass the Portal, or something, but I'm not sure...
> 
> I'm not sure guard is sufficiently flexible to allow this. Perhaps one 
> of the guard replacements that is being worked on will help? mg, can 
> you comment? Also, indigo, can you comment on the session system you 
> wrote and/or perhaps turn it into an example or a module?

Hmm, I don't think there's any way of handling cookie logins right now
except maybe redirecting to the __login__ URL with the username and
password as query params. But yuck!

One of the problems with guard is that there is no API exposed. It might
be nice if guard remembered an IGuard interface for application code to
use. What that would look like and how it would behave is something I
have not considered.

> > I've scanned the various examples, both in the distribution and in
> > the Nevow sandbox, but nothing seems to do what I want. Can anyone
> > give me some pointers?
> 
(Continue reading)


Gmane