Idea: Webshare

R

Robert Klemme

<snip>totally reasonable stuff</snip>

That sums it up very nicely!

Kind regards

robert
 
P

Patrick May

Hello,

I wasn't able to make this continuation trick work for me. It flip
flops -- it works the first time, crashes the second time, then
mod_fastcgi restarts the process and the cycle repeats.

I wish I could make these continuations work, though.

Cheers,

Patrick


Time to make it make sense.

Thought's this was intersting. On Matz's blog there was this snippet:

require 'cgi'
require 'fcgi.so'
class CGI
class Fast < CGI
CONTINUATION = []
def Fast::new(*args)
at_exit do
if CONTINUATION[0]
CONTINUATION[0].call
end
end
callcc do |c|
CONTINUATION[0] = c
end
fcgi = FCGI::accept
unless fcgi CONTINUATION[0] = nil
exit
end
$defout = fcgi.out super(*args)
end
end
end

Does that make sense? Here's what matz says about it:

<quote>
About how to make correction of the existing CGI program minimum and
make it
FastCGI correspondence

Before, such a trick has been written.

[ above code here ]

I change "require'cgi'" into "require'fcgi'" and think that remarkable
CGI
will operate as it is only by rewriting "CGI.new" to "CGI::Fast.new."
</quote>

T.
 
Y

Yukihiro Matsumoto

Hi,

In message "fastcgi & continuations (Re: Idea: Webshare)"

|I wasn't able to make this continuation trick work for me. It flip
|flops -- it works the first time, crashes the second time, then
|mod_fastcgi restarts the process and the cycle repeats.
|
|I wish I could make these continuations work, though.

Need more info. Operating system, interpreter version, Apache version
etc.

matz.
 
P

Patrick May

Hi,

In message "fastcgi & continuations (Re: Idea: Webshare)"
on Tue, 31 Aug 2004 15:14:29 +0900, Patrick May

|I wasn't able to make this continuation trick work for me. It flip
|flops -- it works the first time, crashes the second time, then
|mod_fastcgi restarts the process and the cycle repeats.
|
|I wish I could make these continuations work, though.

Need more info. Operating system, interpreter version, Apache version
etc.

Here's a simple example of the bug(?). Save this as fast.rb:

class Server
CONTINUATION = []
def Server::new(*args)
at_exit do
puts 'at_exit'
if CONTINUATION[0]
CONTINUATION[0].call
end
end

callcc do |c|
CONTINUATION[0] = c
end

puts 'Do you want to continue?'
answer = gets

if (answer.strip == 'no')
CONTINUATION[0] = nil
end
end
end

server = Server.new

Here's what happens when I run this script. Note that I am typing the
'yes' and 'no' in this example:

[laputa:~/programming/narf-servers] patsplat% ruby fast.rb
Do you want to continue?
no
at_exit
[laputa:~/programming/narf-servers] patsplat% ruby fast.rb
Do you want to continue?
yes
at_exit
Do you want to continue?
yes
fast.rb:24: compile error (SyntaxError)
fast.rb:24: [BUG] Bus Error
ruby 1.8.1 (2003-12-25) [powerpc-darwin]

Abort
[laputa:~/programming/narf-servers] patsplat% ruby --version
ruby 1.8.1 (2003-12-25) [powerpc-darwin]
[laputa:~/programming/narf-servers] patsplat%

Cheers,

Patrick
 
P

Patrick May

Let me throw you a wrinkle to think about.

File uploads. If you adopt a model where you are passing a request
object
to the webapp, and the webapp may not even be on the same machine as
the
webserver, what is the best way to handle uploaded files?

You can't just create a tempfile like the current CGI does. Do you
transfer
the data with the request, but then write it to tempfiles on the other
side? Does Drb provide a way that one could write the uploaded files
to
tempfiles on the server, but that one could access the tempfiles via
the
request object in the webapp? Could be cool. Might be a bad idea.

Do you do this? Why would not pass the whole request through, like a
proxy server?

Cheers,

Patrick
 
P

paul vudmaska

Seems to me there is good reason to seperate response from request,
for historical reasons as well as practical/semantic ones. Seperating
data coming in from data going out seems good enough reason to me(and
I also don't see the code redundancy between them).

Coming from the m$ asp world, cgi.rb was the one (of very few) big
burr in my side. Going back to asp of late has been comforting in that
respect (if only that! i want my
dbi,rexml,interpolation,heredoc,dynamic includes... :). I'd wager that
if ruby's cgi were implemented in similar fashion there would be far
fewer posts(from experienced and inexperienced coders) on here
regarding it.

//data in - this aint an array unless i want it to be
sform = Request.Form('var') // overrides Url
surl = Request.Url('var') //asp uses querystring..too long

Session('var') = surl //cant remember how to do that in ruby but it
aint clean.

//out
Response.Write(Session('var'))//puts works but this is more readable


All that seems obvious/transparent to me. It is tried and true
method(at least the distinct request/response) in every app server
i've used (cold fusion,asp,zope,.net,jsp...). To me, these things are
fundamental and wont be easily(or elegantly) extricated from the basic
workings of a web app - data in - data out - that's what we do as web
developers.

As far as an abstraction layer for backend data, that would be a huge
win for the ruby web crowd. Setting a var that would allow me to
say... hold session vars in a db rather than in ram or a file would be
great. I realize the new version has memorystore/pstore etc. Whichever
one you use, the implementation should be the same or similar.

What about application variables? Did i miss them in my ruby
adventures? I sure like/use them in asp/cf.

All web app servers i've seen have caching mechanisms baked in deep
and getting deeper.

Seems to me much could can still be learned from other mature web app
servers. Like them or not, each of them have their wins and warts.
Ruby's cgi is a wart,imo (and i truly mean no dis to the guy/gals
who wrote/write it - i run across few with that level of programming
skill in my world - i just dont like using it) Asp's implementation of
cgi is the best i've used. So there, i said it ;)

peace
 
P

Patrick May

Hello,

sform = Request.Form('var') // overrides Url
surl = Request.Url('var') //asp uses querystring..too long

Session('var') = surl //cant remember how to do that in ruby but it
aint clean.

//out
Response.Write(Session('var'))//puts works but this is more readable

In implementing those 3, you will need to tie them together with one
controlling object. In Narf I call that controlling object Web:):CGI).
Do this:

Request = Response = Web
Session = Web::session

Request['var']
Response << 'output' + Session['key']

and pretend the other methods don't exist.

~ Patrick
 
P

Patrick May

Hello,

This seems to be a powerpc bug. Here is a more simple example:

continuation = []
at_exit{
puts 'at_exit'
continuation[0].call unless continuation[0].nil?
}
callcc{ |c|
continuation[0] = c
}
puts 'running'

This code runs in the expected continuous loop on linux. On my mac
(10.2) I get the error:

[~/programming/narf] patsplat% ruby bug.rb
running
at_exit
running
bug.rb:9: compile error (SyntaxError)
bug.rb:9: [BUG] Bus Error
ruby 1.8.1 (2003-12-25) [powerpc-darwin]

Abort
[~/programming/narf] patsplat%

Does this happen on any other platform? Is this an OS X limitation?

Cheers,

Patrick
 
T

T. Onoma

Hmm...you may want to take this up on ruby-core.

T.


This seems to be a powerpc bug. Here is a more simple example:

continuation = []
at_exit{
puts 'at_exit'
continuation[0].call unless continuation[0].nil?
}
callcc{ |c|
continuation[0] = c
}
puts 'running'

This code runs in the expected continuous loop on linux. On my mac
(10.2) I get the error:

[~/programming/narf] patsplat% ruby bug.rb
running
at_exit
running
bug.rb:9: compile error (SyntaxError)
bug.rb:9: [BUG] Bus Error
ruby 1.8.1 (2003-12-25) [powerpc-darwin]

Abort
[~/programming/narf] patsplat%

Does this happen on any other platform? Is this an OS X limitation?

Cheers,

Patrick
 
Y

Yukihiro Matsumoto

Sorry for being so slow.

In message "Re: eval function efficiency"

|I am using the eval function excessively in one of my programs. Is there
|any real performance drains from using it? Thanks,

If you call eval repeatedly, compile cost from string can be a
burden. Try avoiding eval within loops.

matz.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,158
Messages
2,570,882
Members
47,414
Latest member
djangoframe

Latest Threads

Top