From: "trans. (T. Onoma)" Date: 2004-11-03T13:53:09+09:00 Subject: Re: fastcgi performance problems and ruby On Tuesday 02 November 2004 11:29 am, Brian Candler wrote: | OK, the 'Singleton pattern'. Always seemed rather pointless to me; if | there's only ever going to be one CGI instance, then you might as well make | all the methods class methods of CGI itself, and use class instance | variables. In fact I asked about that (albeit not in relation to CGI) on the list a couple weeks ago and three options were brought up: Singleton _pattern_, Module functions, as you suggest, and an Object with virtual/singleton class. All are very similar but there does turn out to be a few important differences. | Well, it seems to me that each request ought to create a different CGI | object, for the simple reason that each HTTP request has a different set of | parameters - and it's the CGI object that represents them. | | I suppose you could 're-use' the previous CGI object, by resetting its | instance variables to the new request, but that's not a very Rubyesque way | of doing things (IMO). I see what your saying, but a Singleton can have open parameters that can be changed in place, too. I have used Singleton CGI myself and it does work. As for the Ruby Way to do it, you certainly have a point, and probably the most OOP tack would be to separate out the part that changes from the part that doesn't. The part that doesn't, i.e. CGI, would then delegate for the part that does, i.e. the Request. Thus only the changing part need to be re-instantiated between requests. Seem reasonable? Nonetheless I'm fairly sure that still won't be as fast as in place changes. | It would be better, I think, to make the object creation faster by not | doing all those slow eval def's each time. For example, if you want to | include the CGI::Html3 module you could first check if it exists, and if it | doesn't then define it (in the slow eval way if that's tidier). Subsequent | requests can just do 'extend CGI::Html3' which is fast. e.g. | | unless defined? Html3 | module Html3 | .. define static methods | end | .. define methods dynamically using eval | end | extend Html3 Certainly would help. But again, if you're after speed.... BTW, look what just popped up on RAA: http://raa.ruby-lang.org/project/apachecgi/ I haven't looked at it yet thought So I'm not sure how it works, but I suspect... T.