Do you just want to do this for the warm fuzzy feeling of still putting java to use or are there some specific requirements which you hope to solve this way? I doubt its possible but its also a pretty bad idea to boot. Why do you want the tremendous memory overhead of java to run something which works just as well or better in the c based ruby interpreter? Use the right tools for the right job. Hammer to drive nails in. Ruby for the web. On 4/27/05, John Wells <lists-y8WhZ5XeQqVfbyii3fMa5/Z4XP/Yx64J@public.gmane.org> wrote:> (Note: I originally posted this on ruby-talk, but thought I''d get a better > set of answers here. I appreciate your time) > > Guys, > > I''m fairly new to the ruby world...one of those being lured over by the > RoR framework. > > As I''ve mentioned in past posts, my company is primarily a Java shop. > While we really like RoR''s speed of development, we''d actually prefer to > be able to use it in our existing servlet containers. > > With Jython, you can indeed run python scripts as servlets. We have, in > fact, used this functionality in the past, but mainly for prototyping > applications that would later become Java-based. > > With RoR and JRuby, however, we''d be interested in writing full-fledged > applications in ruby, and then running them within the container. I''ve > searched the web for information on how to do this or whether it''s even > possible, yet haven''t run across a good resource yet. > > Can anyone tell me A. if it''s possible, and B. if not, what remains to be > done with JRuby to make it possible? If it may be possible in the future, > but work remains to be done, I''d like to get involved and help out. > > Thanks for your time. > > John > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Tobi http://www.snowdevil.ca - Snowboards that don''t suck http://www.hieraki.org - Open source book authoring http://blog.leetsoft.com - Technical weblog
(Note: I originally posted this on ruby-talk, but thought I''d get a better set of answers here. I appreciate your time) Guys, I''m fairly new to the ruby world...one of those being lured over by the RoR framework. As I''ve mentioned in past posts, my company is primarily a Java shop. While we really like RoR''s speed of development, we''d actually prefer to be able to use it in our existing servlet containers. With Jython, you can indeed run python scripts as servlets. We have, in fact, used this functionality in the past, but mainly for prototyping applications that would later become Java-based. With RoR and JRuby, however, we''d be interested in writing full-fledged applications in ruby, and then running them within the container. I''ve searched the web for information on how to do this or whether it''s even possible, yet haven''t run across a good resource yet. Can anyone tell me A. if it''s possible, and B. if not, what remains to be done with JRuby to make it possible? If it may be possible in the future, but work remains to be done, I''d like to get involved and help out. Thanks for your time. John
Tobias Luetke said:> Do you just want to do this for the warm fuzzy feeling of still > putting java to use or are there some specific requirements which you > hope to solve this way? > > I doubt its possible but its also a pretty bad idea to boot. Why do > you want the tremendous memory overhead of java to run something which > works just as well or better in the c based ruby interpreter? > > Use the right tools for the right job. Hammer to drive nails in. Ruby > for the web.Specific requirements. - We''ve got a number of Java applications already running in servlet containers. Using JRuby within the container would mean we could make native calls into these applications...very much easing integration. - Reusing the container itself would allow us to install at our various client sides with minimal impact. - Number one benefit: the stateful nature of Java servlets...i.e., servlets maintain state between requests. It''s a very nice feature to have, and one that RoR can''t provide as easily. Thanks for your input. John
John Wells wrote:> - We''ve got a number of Java applications already running in servlet > containers. Using JRuby within the container would mean we could make > native calls into these applications...very much easing integration.This sounds nice, but jruby is very immature. I tried to use it as a Java bridge but quickly ran into its lack of sockets support. Have you seen rjb? It''s also young and I haven''t worked with it yet, but it looks like a promising Ruby/Java bridge.> - Reusing the container itself would allow us to install at our various > client sides with minimal impact.This is the largest advantage IMO: easy deployment and low migration effort. It''s easier for your customers (and your sysadmins) to swallow.> - Number one benefit: the stateful nature of Java servlets...i.e., > servlets maintain state between requests. It''s a very nice feature to > have, and one that RoR can''t provide as easily.This has code smell, but when you''re running under FastCGI you can maintain state between requests. It''s probably better to just use the session instead. Also consider memcached if you want to maintain application (non-session-specific) state in a clustered environment. Another option: use a FastCGI servlet. Resin has a nice implementation. Best, jeremy
> Java bridge but quickly ran into its lack of sockets support. Have you > seen rjb? It''s also young and I haven''t worked with it yet, but it > looks like a promising Ruby/Java bridge.I''ve had some luck using this to get my rails app to use jasperreports. rjb is pretty slick, and decently fast as it uses jni to do the calls to the jvm.> Another option: use a FastCGI servlet. Resin has a nice implementation. >If you know how to make this work, please let me know!! I tried for a day but couldn''t get anything talking to each other. I think my problem was in properly setting up a standalone fcgi server running my rails app outside of any web server environment (apache, lighttpd, webrick). I tried using spawn-fcgi but maybe I just configured it incorrectly. Thanks, jason
John Wells wrote:> Jeremy Kemper said: >>Another option: use a FastCGI servlet. Resin has a nice implementation. > > Thanks for your reply. If you don''t mind, could you explain the above a > little more? I''m not sure exactly how this could benefit me.It wouldn''t help with reusing your existing Java code, but would ease deployment effort since it may obviate the need to introduce new services just for Rails. Also, you may gain something from request handling in a servlet since you can muck with the request before it hits Rails and the response as it''s sent to the client. You could even do some rudimentary IPC by mucking with HTTP headers. jeremy
Jason Foreman wrote:> If you know how to make this work, please let me know!! I tried for a > day but couldn''t get anything talking to each other. > > I think my problem was in properly setting up a standalone fcgi server > running my rails app outside of any web server environment (apache, > lighttpd, webrick). I tried using spawn-fcgi but maybe I just > configured it incorrectly.I haven''t set this up, but heard second-hand that Resin''s FastCGI servlet implements the spec very well. spawn-fcgi is the way to go for launching an standalone server for public/dispatch.fcgi. Perhaps these links will help, though I imagine you''ve seen them already: http://www.caucho.com/resin-3.0/thirdparty/php.xtp http://www.lighttpd.net/download/spawn-fcgi.txt Best, jeremy
Jeremy Kemper said:> Another option: use a FastCGI servlet. Resin has a nice implementation.Jeremy, Thanks for your reply. If you don''t mind, could you explain the above a little more? I''m not sure exactly how this could benefit me. Thanks! John
Jeremy Kemper said:> It wouldn''t help with reusing your existing Java code, but would ease > deployment effort since it may obviate the need to introduce new > services just for Rails. > > Also, you may gain something from request handling in a servlet since > you can muck with the request before it hits Rails and the response as > it''s sent to the client. You could even do some rudimentary IPC by > mucking with HTTP headers.Gotcha. I looked it up and understand what''s it''s trying to accomplish. Doesn''t appear to be an open implementation for Tomcat (so far), and since Resin is commercial I doubt we''d be able to use that. I may look at attempting to whip something up myself. Thanks for the pointer. John
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 John Wells wrote:> - Number one benefit: the stateful nature of Java servlets...i.e., > servlets maintain state between requests. It''s a very nice feature to > have, and one that RoR can''t provide as easily.Technically, the nature of HTPP prohibits stateful transactions... thus the use of @session. There really isn''t much difference. @session or memcache can both help to preserve state for you. - -- David Morton Maia Mailguard server side anti-spam/anti-virus solution: http://www.maiamailguard.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCcDWHSIxC85HZHLMRAuZFAJ9ijHEnz6Wastj+C9IumdpH3dzaZgCfYdJt ysS/j93cl1h9R62mG8FI8QY=4u/f -----END PGP SIGNATURE-----
On 4/27/05, John Wells <lists-y8WhZ5XeQqVfbyii3fMa5/Z4XP/Yx64J@public.gmane.org> wrote:> - Number one benefit: the stateful nature of Java servlets...i.e., > servlets maintain state between requests. It''s a very nice feature to > have, and one that RoR can''t provide as easily.Are servlets truly stateful? My belief is that they are stateless but have the ability to store state in a session object, much like Rails. Some app servers also provide the ability to share session state across a web farm. But I don''t believe servlets are actually stateful across requests. That would actually be a huge negative as far as scalability is concerned. -- Chris Brooks http://www.chrisbrooks.org
Chris Brooks said:> Are servlets truly stateful? My belief is that they are stateless but > have the ability to store state in a session object, much like Rails. > Some app servers also provide the ability to share session state > across a web farm. But I don''t believe servlets are actually stateful > across requests. That would actually be a huge negative as far as > scalability is concerned.They are. Typically, a set number of instances of a servlet will be loaded in a servlet container, and these servlet instances continue to exist between request/response cycles. They indeed have the capability to use an HttpSession object, much like rails, but they are also stateful where rails is not. See http://java.sun.com/j2ee/1.4/docs/tutorial/doc/Servlets4.html#wp73579 for more info. John
John Wells wrote:> Chris Brooks said: >>Are servlets truly stateful? My belief is that they are stateless but >>have the ability to store state in a session object, much like Rails. >>Some app servers also provide the ability to share session state >>across a web farm. But I don''t believe servlets are actually stateful >>across requests. That would actually be a huge negative as far as >>scalability is concerned. > > They are. Typically, a set number of instances of a servlet will be loaded > in a servlet container, and these servlet instances continue to exist > between request/response cycles. They indeed have the capability to use > an HttpSession object, much like rails, but they are also stateful where > rails is not./rails is/CGI, mod_ruby, and FastCGI are/ Action Pack lives in any CGI-like environment, including a servlet-like container should one exist. And one does: WEBrick. jeremy
On 4/28/05, Jeremy Kemper <jeremy-w7CzD/W5Ocjk1uMJSBkQmQ@public.gmane.org> wrote:> John Wells wrote: > > They are. Typically, a set number of instances of a servlet will be loaded > > in a servlet container, and these servlet instances continue to exist > > between request/response cycles. They indeed have the capability to use > > an HttpSession object, much like rails, but they are also stateful where > > rails is not. > > /rails is/CGI, mod_ruby, and FastCGI are/ > > Action Pack lives in any CGI-like environment, including a servlet-like > container should one exist. And one does: WEBrick.I think we are possibly talking about different things when we say "stateless". When I say servlets are stateless, I''m referring to end user state. Certainly there''s a lifecycle for servlet instances that may result in a servlet instance staying alive over a sequence of HTTP requests/responses. But certainly no user state is saved in the servlet, which is what I was originally referring to. That''s what session state is for. -- Chris Brooks http://www.chrisbrooks.org
Chris Brooks wrote:> On 4/28/05, Jeremy Kemper <jeremy-w7CzD/W5Ocjk1uMJSBkQmQ@public.gmane.org> wrote: > >>John Wells wrote: >> >>>They are. Typically, a set number of instances of a servlet will be loaded >>>in a servlet container, and these servlet instances continue to exist >>>between request/response cycles. They indeed have the capability to use >>>an HttpSession object, much like rails, but they are also stateful where >>>rails is not. >> >>/rails is/CGI, mod_ruby, and FastCGI are/ >> >>Action Pack lives in any CGI-like environment, including a servlet-like >>container should one exist. And one does: WEBrick. > > I think we are possibly talking about different things when we say > "stateless". When I say servlets are stateless, I''m referring to end > user state.Indeed.> Certainly there''s a lifecycle for servlet instances that > may result in a servlet instance staying alive over a sequence of HTTP > requests/responses.I think this is what the OP is talking about. It''s similar to Application state in the MS world.> But certainly no user state is saved in the > servlet, which is what I was originally referring to. That''s what > session state is for.Yup; servlet lifetime/application state and HTTP sessions are orthogonal. jeremy
Chris Brooks said:>> Action Pack lives in any CGI-like environment, including a servlet-like >> container should one exist. And one does: WEBrick. > > I think we are possibly talking about different things when we say > "stateless". When I say servlets are stateless, I''m referring to end > user state. Certainly there''s a lifecycle for servlet instances that > may result in a servlet instance staying alive over a sequence of HTTP > requests/responses. But certainly no user state is saved in the > servlet, which is what I was originally referring to. That''s what > session state is for.Chris, yup...I''m not interested in maintaining user state in a servlet...I do use sessions for that. However, having servlets be stateful has benefits, particularly if your application has to do any resource intensive opening of connections or what have you. As a simplistic example, suppose opening a connection to your database takes two seconds each time. In a Ruby/CGI environment, you''d be forced to open this connection on every user request that required database access, but in the servlet world you could open it only once, when the servlet container was started. Jeremy, so you''re saying WEBrick is a way of maintaining state between requests? Is it fast enough for production use? I need to examine this further, I suppose...my impression of WEBrick was that it was a ruby-based web server you would primarily use for testing Rails applications without having to set up Apache/mod_ruby. Thanks for all the info. John
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 John Wells wrote:> Chris, yup...I''m not interested in maintaining user state in a servlet...I > do use sessions for that. However, having servlets be stateful has > benefits, particularly if your application has to do any resource > intensive opening of connections or what have you. As a simplistic > example, suppose opening a connection to your database takes two seconds > each time. In a Ruby/CGI environment, you''d be forced to open this > connection on every user request that required database access, but in the > servlet world you could open it only once, when the servlet container was > started.Fastcgi and mod_ruby both keep the database connection open... no difference there... - -- David Morton Maia Mailguard server side anti-spam/anti-virus solution: http://www.maiamailguard.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCcmV/SIxC85HZHLMRAn0dAKCVF9lDTcdRv/8+0xOA5ZZD2pER6ACcCP3C X17CLSIumabu37McwUzWWsA=Xahf -----END PGP SIGNATURE-----
John Wells wrote:> Jeremy, so you''re saying WEBrick is a way of maintaining state between > requests? Is it fast enough for production use? I need to examine this > further, I suppose...my impression of WEBrick was that it was a ruby-based > web server you would primarily use for testing Rails applications without > having to set up Apache/mod_ruby.WEBrick is the only option for Rails deployment that gives you something that looks like a servlet container. But this is hardly germane; the question is what will suit your needs, not what quacks like a servlet. You''ll find that FastCGI is an excellent option. Each FastCGI instance is a long-running process, so resource management is not an issue. You cannot (directly) share state among instances, but this is true for any clustered application. And FastCGI is dead-easy to cluster. Front your app with the brilliant lighttpd; back it with an army of FastCGI nodes. jeremy
Jeremy Kemper <jeremy-w7CzD/W5Ocjk1uMJSBkQmQ@public.gmane.org> said:> WEBrick is the only option for Rails deployment that gives you something > that looks like a servlet container. But this is hardly germane; the > question is what will suit your needs, not what quacks like a servlet. > > You''ll find that FastCGI is an excellent option. Each FastCGI instance > is a long-running process, so resource management is not an issue. You > cannot (directly) share state among instances, but this is true for any > clustered application. And FastCGI is dead-easy to cluster. Front your > app with the brilliant lighttpd; back it with an army of FastCGI nodes.Jeremy, Thanks very much for the helpful info. I''ll look hard at FastCGI. John