Hubert Łępicki
2009-Jan-12 11:54 UTC
Thread safety in 2.2.2 - Thread.new { do_sth } to do background job?
Hi guys, I am writing application that is converting files from one format to another. The process takes some time for larger files, and I want to run it in backround. My application is running in threaded mode (enabled in environment.rb) and I know Rails 2.2.2 is thread safe. Can I simply do in my controller: def create @file = MyFile.new(params[:file]) @file.save Thread.new { @file.convert } end This seems to be working fine, but should I expect any problems or this is allowed in Rails 2.2.2, please? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hubert Łępicki
2009-Jan-13 22:53 UTC
Re: Thread safety in 2.2.2 - Thread.new { do_sth } to do background job?
Pff, what''s wrong with you guys -- each time I need answer: nothing! On 12 Sty, 12:54, Hubert Łępicki <hubert.lepi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi guys, > > I am writing application that is converting files from one format to > another. The process takes some time for larger files, and I want to > run it in backround. My application is running in threaded mode > (enabled in environment.rb) and I know Rails 2.2.2 is thread safe. > > Can I simply do in my controller: > > def create > @file = MyFile.new(params[:file]) > @file.save > Thread.new{ > @file.convert > } > end > > This seems to be working fine, but should I expect any problems or > this is allowed in Rails 2.2.2, please?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Maurício Linhares
2009-Jan-13 23:01 UTC
Re: Thread safety in 2.2.2 - Thread.new { do_sth } to do background job?
Maybe no one has a real answer for you :) From my experience, if you're running ActiveRecord code, you could have a problem. I tried to use active record on non controller threads (even using with_connection) and it didn't work. If you're not using ActiveRecord, it shoudn't be an issue, just don't forget that the MRI isn't really concurrent and you'll just get real concurrency running on JRuby. - Maurício Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) 2009/1/13 Hubert Łępicki <hubert.lepicki@gmail.com>:> > Pff, > > what's wrong with you guys -- each time I need answer: nothing! > > > > On 12 Sty, 12:54, Hubert Łępicki <hubert.lepi...@gmail.com> wrote: >> Hi guys, >> >> I am writing application that is converting files from one format to >> another. The process takes some time for larger files, and I want to >> run it in backround. My application is running in threaded mode >> (enabled in environment.rb) and I know Rails 2.2.2 is thread safe. >> >> Can I simply do in my controller: >> >> def create >> @file = MyFile.new(params[:file]) >> @file.save >> Thread.new{ >> @file.convert >> } >> end >> >> This seems to be working fine, but should I expect any problems or >> this is allowed in Rails 2.2.2, please? > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hubert Łępicki
2009-Jan-13 23:07 UTC
Re: Thread safety in 2.2.2 - Thread.new { do_sth } to do background job?
Thanks - well this may be issue. If it was easy to find solutions on google I would do it myself. I am using ActiveRecord. The only problem I have noticed so far is that rails turn off class reloading when config.threadsafe is enabled - and it makes my development pain (need to restart server each time after I change code). On 14 Sty, 00:01, "Maurício Linhares" <mauricio.linha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Maybe no one has a real answer for you :) > > From my experience, if you''re running ActiveRecord code, you could > have a problem. I tried to use active record on non controller threads > (even using with_connection) and it didn''t work. If you''re not using > ActiveRecord, it shoudn''t be an issue, just don''t forget that the MRI > isn''t really concurrent and you''ll just get real concurrency running > on JRuby. > > - > Maurício Linhareshttp://alinhavado.wordpress.com/(pt-br) |http://blog.codevader.com/(en) > > 2009/1/13 Hubert Łępicki <hubert.lepi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > > Pff, > > > what''s wrong with you guys -- each time I need answer: nothing! > > > On 12 Sty, 12:54, Hubert Łępicki <hubert.lepi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Hi guys, > > >> I am writing application that is converting files from one format to > >> another. The process takes some time for larger files, and I want to > >> run it in backround. My application is running in threaded mode > >> (enabled in environment.rb) and I know Rails 2.2.2 is thread safe. > > >> Can I simply do in my controller: > > >> def create > >> @file = MyFile.new(params[:file]) > >> @file.save > >> Thread.new{ > >> @file.convert > >> } > >> end > > >> This seems to be working fine, but should I expect any problems or > >> this is allowed in Rails 2.2.2, please?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Xie Hanjian
2009-Jan-14 02:24 UTC
Re: Thread safety in 2.2.2 - Thread.new { do_sth } to do background job?
Hi Hubert, If @file.convert is high cpu intensive task, you''d better use workers at background with a queue, or try jruby since MRI use green threads. Jan * Hubert Łępicki <hubert.lepicki-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> [2009-01-12 03:54:34 -0800]:> > Hi guys, > > I am writing application that is converting files from one format to > another. The process takes some time for larger files, and I want to > run it in backround. My application is running in threaded mode > (enabled in environment.rb) and I know Rails 2.2.2 is thread safe. > > Can I simply do in my controller: > > def create > @file = MyFile.new(params[:file]) > @file.save > Thread.new { > @file.convert > } > end > > This seems to be working fine, but should I expect any problems or > this is allowed in Rails 2.2.2, please? > > --~--~---------~--~----~------------~-------~--~----~ > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > -~----------~----~----~----~------~----~------~--~----- jan=callcc{|jan|jan};jan.call(jan)
AD
2009-Jan-14 03:49 UTC
Re: Thread safety in 2.2.2 - Thread.new { do_sth } to do background job?
i thought AR was thread-safe in 2.2 ? On Tue, Jan 13, 2009 at 9:24 PM, Xie Hanjian <jan.h.xie@gmail.com> wrote:> Hi Hubert, > > If @file.convert is high cpu intensive task, you'd better use workers at > background with a queue, or try jruby since MRI use green threads. > > Jan > > * Hubert Łępicki <hubert.lepicki@gmail.com> [2009-01-12 03:54:34 -0800]: > > > > > Hi guys, > > > > I am writing application that is converting files from one format to > > another. The process takes some time for larger files, and I want to > > run it in backround. My application is running in threaded mode > > (enabled in environment.rb) and I know Rails 2.2.2 is thread safe. > > > > Can I simply do in my controller: > > > > def create > > @file = MyFile.new(params[:file]) > > @file.save > > Thread.new { > > @file.convert > > } > > end > > > > This seems to be working fine, but should I expect any problems or > > this is allowed in Rails 2.2.2, please? > > > > > > -- > jan=callcc{|jan|jan};jan.call(jan) >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Xie Hanjian
2009-Jan-14 05:24 UTC
Re: Thread safety in 2.2.2 - Thread.new { do_sth } to do background job?
* AD <straightflush-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> [2009-01-13 22:49:59 -0500]:> i thought AR was thread-safe in 2.2 ?It supposed to be. I have a small app use threads with sqlite3, and it runs well until now :-) Jan> > On Tue, Jan 13, 2009 at 9:24 PM, Xie Hanjian <jan.h.xie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi Hubert, > > > > If @file.convert is high cpu intensive task, you''d better use workers at > > background with a queue, or try jruby since MRI use green threads. > > > > Jan > > > > * Hubert Łępicki <hubert.lepicki-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> [2009-01-12 03:54:34 -0800]: > > > > > > > > Hi guys, > > > > > > I am writing application that is converting files from one format to > > > another. The process takes some time for larger files, and I want to > > > run it in backround. My application is running in threaded mode > > > (enabled in environment.rb) and I know Rails 2.2.2 is thread safe. > > > > > > Can I simply do in my controller: > > > > > > def create > > > @file = MyFile.new(params[:file]) > > > @file.save > > > Thread.new { > > > @file.convert > > > } > > > end > > > > > > This seems to be working fine, but should I expect any problems or > > > this is allowed in Rails 2.2.2, please? > > > > > > > > > -- > > jan=callcc{|jan|jan};jan.call(jan) > > > > --~--~---------~--~----~------------~-------~--~----~ > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > -~----------~----~----~----~------~----~------~--~--- >-- jan=callcc{|jan|jan};jan.call(jan)