Hi,
I'm not using Rails: just a standalone 'Webrick' Server. I have a very
simple Servlet which is serving text files: it works, but I notice that
it seeming to be two (maybe related?) things I need to fix:
1. It is 'chomping' the text files: removing any '\r', leaving '\n'
chars at the end of my response string.
2. It runs slower than Tomcat (fair enough), but *really* slow (~4-5
times slower) when I access over a VPN (or a different n/w): the
VPN/other n/w _seems_ to be the link here. When running on a local n/w
(or directly on the box itself), there is no noticeable difference in
performance: but there a distinctive 5-10 second lag on the browser in
the case of VPN/different n/w.
So any hints on optimizing the Ruby Servlet greatly appreciated - you
can see from the Java version that I'm really not interested in doing
_anything_ to the data - I just want to delivery as fast as possible -
in tact.
The Webrick server is running on Ruby 1.8.x on a Windows 2000 box.
Anyway , here's the servlets (stripped down to bare function).
--Ruby Servlet
...
def do_GET(request, response)
r=""; #probably not necessary...but habits from static languages
carry-over
file_data=<myfilepath>
f=File.open(file_data,"r"); # load as pure bytes like the java
version?how?
r << f.read
f.close;
response.body=r;
response.status=200;
response['Content-Type'] ="text/plain"
end
...
--End of Ruby Servlet
--Equivalent Java Servlet
...doGet(HttpServletRequest request, HttpServletResponse response)...
out=response.getOutputStream()
f=<myfilepath>
...
int len=bytes;
InputStream in = new FileInputStream(f);
byte[] buf = new byte[len];
while ((len = in.read(buf)) > 0)
{
out.write(buf,0,len);
}
out.flush();
out.close();
in.close();
...
--End of Java Servlet
Cheers
John
And also just for proof , here's the timing from 2 'curl' invocations
running over a VPN to get at the server.
···
==
curl "http://server:8080/tomcat" -o tomcat.out
% Total % Received % Xferd Average Speed Time Time Time
Current
Dload Upload Total Spent Left
Speed
100 27594 100 27594 0 0 10336 0 0:00:02 0:00:02 --:--:--
10652
curl "http://server:2000/webrick" -o webrick.out
% Total % Received % Xferd Average Speed Time Time Time
Current
Dload Upload Total Spent Left
Speed
100 27394 100 27394 0 0 2876 0 0:00:09 0:00:09 --:--:--
6173
The file in question was exactly 200 lines, and the correct size on disk
is '27594' NOT '27394': 'od -c' shows that the Ruby Servlet is
'chomping' on an extra '\r' character...
--
Posted via http://www.ruby-forum.com/.