linux user
2006-Aug-07 13:52 UTC
[Rails] Store SOAP::RPC::Driver in user session throws TypeError
Hi All I have a requirement to consume a 3rd party web service from my Rails application. I am doing this in my action require ''soap/wsdlDriver'' factory = SOAP::WSDLDriverFactory.new(TRANSIDIOM_WSDL_URL) soap = factory.create_rpc_driver soap.wiredump_file_base="#{RAILS_ROOT}/log/transidiom.log" param = %(<Request name="com.wm.ccv.rpgrouter.seagull.CustomerProfileResCom"> <Input> <CompanyCode>110</CompanyCode> <CustomerNumber>2442</CustomerNumber> <UserName>ccvdev2</UserName> <Password>ccvdev2</Password> <LibrarySuffix>ORC</LibrarySuffix> <targetHost>wmasprod</targetHost> </Input> </Request>) result = soap..retrieveCustomerData(param) I get the expected result, but the real problem is performance since I have to re-create the rpc-driver to the same service on each request. So I try and store the soap object which is SOAP::RPC::Driver type. session[:soap] = soap and I get TypeError (singleton can''t be dumped): C:/ruby/lib/ruby/1.8/pstore.rb:348:in `dump'' C:/ruby/lib/ruby/1.8/pstore.rb:348:in `dump'' C:/ruby/lib/ruby/1.8/pstore.rb:326:in `transaction'' C:/ruby/lib/ruby/1.8/cgi/session/pstore.rb:90:in `update'' C:/ruby/lib/ruby/1.8/cgi/session/pstore.rb:97:in `close'' C:/ruby/lib/ruby/1.8/cgi/session.rb:330:in `close'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:984:in `close_session'' Now ofcourse I realize that RPC Driver has some singleton object or anonymous class/method which can''t be serialized hence the TypeError. My question is what can I do to improve the performance and reduce the overhead of creating new RPC Driver objects on each request. Thanks -daya -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060807/8e13c945/attachment.html
Ola Bini
2006-Aug-07 14:01 UTC
[Rails] Store SOAP::RPC::Driver in user session throws TypeError
linux user wrote:> Hi All > > I have a > requirement to consume a 3rd party web service from my Rails application. I am doing this > in my action > > require ''soap/wsdlDriver'' > factory = SOAP::WSDLDriverFactory.new(TRANSIDIOM_WSDL_URL) > soap = factory.create_rpc_driver > soap.wiredump_file_base="#{RAILS_ROOT}/log/transidiom.log" > > param = %(<Request > name="com.wm.ccv.rpgrouter.seagull.CustomerProfileResCom"> <Input> > <CompanyCode>110</CompanyCode> <CustomerNumber>2442</CustomerNumber> > <UserName>ccvdev2</UserName> <Password>ccvdev2</Password> > <LibrarySuffix>ORC</LibrarySuffix> <targetHost>wmasprod</targetHost> > </Input> </Request>) > > result = soap..retrieveCustomerData(param) > > I get the expected result, but the real problem is performance since I > have to re-create the rpc-driver to the same service on each request. So > I try and store the soap object which is SOAP::RPC::Driver type. > > session[:soap] = soap > > and I get TypeError (singleton can''t be dumped): > C:/ruby/lib/ruby/1.8/pstore.rb:348:in `dump'' > C:/ruby/lib/ruby/1.8/pstore.rb:348:in `dump'' > C:/ruby/lib/ruby/1.8/pstore.rb:326:in `transaction'' > C:/ruby/lib/ruby/1.8/cgi/session/pstore.rb:90:in `update'' > C:/ruby/lib/ruby/1.8/cgi/session/pstore.rb:97:in `close'' > C:/ruby/lib/ruby/1.8/cgi/session.rb:330:in `close'' > C:/ruby/lib/ruby/gems/1.8/gems/actionpack- > 1.12.1/lib/action_controller/base.rb:984:in `close_session'' > > Now ofcourse I realize that RPC Driver has some singleton object or > anonymous class/method which can''t be serialized hence the TypeError. My > question is what can I do to improve the performance and reduce the > overhead of creating new RPC Driver objects on each request. > > > Thanks > -daya > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/railsYou don''t store the driver itself in the session but in global singleton objects. That''s the approach I used not long time ago for exactly this kind of problem. I just had someting like this in my model class if @@driver.nil? @@driver = SoapWsdlDriver.new end @@driver.customWebServiceCall -- Ola Bini (http://ola-bini.blogspot.com) JvYAML, RbYAML, JRuby and Jatha contributor System Developer, Karolinska Institutet (http://www.ki.se) OLogix Consulting (http://www.ologix.com) "Yields falsehood when quined" yields falsehood when quined.
linux user
2006-Aug-07 15:08 UTC
[Rails] Store SOAP::RPC::Driver in user session throws TypeError
Ola, this is a Good idea but can it give rise race conditions?? or are there anyother implications which might be painful to debug/fix in the long run? On 8/7/06, Ola Bini <ola.bini@ki.se> wrote:> > linux user wrote: > > Hi All > > > > I have a > > requirement to consume a 3rd party web service from my Rails > application. I am doing this > > in my action > > > > require ''soap/wsdlDriver'' > > factory = SOAP::WSDLDriverFactory.new(TRANSIDIOM_WSDL_URL) > > soap = factory.create_rpc_driver > > soap.wiredump_file_base="#{RAILS_ROOT}/log/transidiom.log" > > > > param = %(<Request > > name="com.wm.ccv.rpgrouter.seagull.CustomerProfileResCom"> <Input> > > <CompanyCode>110</CompanyCode> <CustomerNumber>2442</CustomerNumber> > > <UserName>ccvdev2</UserName> <Password>ccvdev2</Password> > > <LibrarySuffix>ORC</LibrarySuffix> <targetHost>wmasprod</targetHost> > > </Input> </Request>) > > > > result = soap..retrieveCustomerData(param) > > > > I get the expected result, but the real problem is performance since I > > have to re-create the rpc-driver to the same service on each request. So > > I try and store the soap object which is SOAP::RPC::Driver type. > > > > session[:soap] = soap > > > > and I get TypeError (singleton can''t be dumped): > > C:/ruby/lib/ruby/1.8/pstore.rb:348:in `dump'' > > C:/ruby/lib/ruby/1.8/pstore.rb:348:in `dump'' > > C:/ruby/lib/ruby/1.8/pstore.rb:326:in `transaction'' > > C:/ruby/lib/ruby/1.8/cgi/session/pstore.rb:90:in `update'' > > C:/ruby/lib/ruby/1.8/cgi/session/pstore.rb:97:in `close'' > > C:/ruby/lib/ruby/1.8/cgi/session.rb:330:in `close'' > > C:/ruby/lib/ruby/gems/1.8/gems/actionpack- > > 1.12.1/lib/action_controller/base.rb:984:in `close_session'' > > > > Now ofcourse I realize that RPC Driver has some singleton object or > > anonymous class/method which can''t be serialized hence the TypeError. My > > question is what can I do to improve the performance and reduce the > > overhead of creating new RPC Driver objects on each request. > > > > > > Thanks > > -daya > > > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > You don''t store the driver itself in the session but in global singleton > objects. That''s the approach I used not long time ago for exactly this > kind of problem. > > I just had someting like this in my model class > if @@driver.nil? > @@driver = SoapWsdlDriver.new > end > @@driver.customWebServiceCall > > > > -- > Ola Bini (http://ola-bini.blogspot.com) > JvYAML, RbYAML, JRuby and Jatha contributor > System Developer, Karolinska Institutet (http://www.ki.se) > OLogix Consulting (http://www.ologix.com) > > "Yields falsehood when quined" yields falsehood when quined. > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060807/a18d36f6/attachment.html
linux user
2006-Aug-07 15:45 UTC
[Rails] Store SOAP::RPC::Driver in user session throws TypeError
On 8/7/06, linux user <fanoflinux@gmail.com> wrote:> > Ola, this is a Good idea but can it give rise race conditions?? or are > there anyother implications which might be painful to debug/fix in the long > run? > > > On 8/7/06, Ola Bini <ola.bini@ki.se> wrote: > > > > linux user wrote: > > > Hi All > > > > > > I have a > > > requirement to consume a 3rd party web service from my Rails > > application. I am doing this > > > in my action > > > > > > require ''soap/wsdlDriver'' > > > factory = SOAP::WSDLDriverFactory.new(TRANSIDIOM_WSDL_URL) > > > soap = factory.create_rpc_driver > > > soap.wiredump_file_base="#{RAILS_ROOT}/log/transidiom.log" > > > > > > param = %(<Request > > > name="com.wm.ccv.rpgrouter.seagull.CustomerProfileResCom"> <Input> > > > <CompanyCode>110</CompanyCode> <CustomerNumber>2442</CustomerNumber> > > > <UserName>ccvdev2</UserName> <Password>ccvdev2</Password> > > > <LibrarySuffix>ORC</LibrarySuffix> <targetHost>wmasprod</targetHost> > > > </Input> </Request>) > > > > > > result = soap..retrieveCustomerData(param) > > > > > > I get the expected result, but the real problem is performance since I > > > > > have to re-create the rpc-driver to the same service on each request. > > So > > > I try and store the soap object which is SOAP::RPC::Driver type. > > > > > > session[:soap] = soap > > > > > > and I get TypeError (singleton can''t be dumped): > > > C:/ruby/lib/ruby/1.8/pstore.rb:348:in `dump'' > > > C:/ruby/lib/ruby/1.8/pstore.rb:348:in `dump'' > > > C:/ruby/lib/ruby/1.8/pstore.rb:326:in `transaction'' > > > C:/ruby/lib/ruby/1.8/cgi/session/pstore.rb:90:in `update'' > > > C:/ruby/lib/ruby/1.8/cgi/session/pstore.rb:97:in `close'' > > > C:/ruby/lib/ruby/1.8/cgi/session.rb:330:in `close'' > > > C:/ruby/lib/ruby/gems/1.8/gems/actionpack- > > > 1.12.1/lib/action_controller/base.rb:984:in `close_session'' > > > > > > Now ofcourse I realize that RPC Driver has some singleton object or > > > anonymous class/method which can''t be serialized hence the TypeError. > > My > > > question is what can I do to improve the performance and reduce the > > > overhead of creating new RPC Driver objects on each request. > > > > > > > > > Thanks > > > -daya > > > > > > > > > > > > > > ------------------------------------------------------------------------ > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > You don''t store the driver itself in the session but in global singleton > > objects. That''s the approach I used not long time ago for exactly this > > kind of problem. > > > > I just had someting like this in my model class > > if @@driver.nil? > > @@driver = SoapWsdlDriver.new > > end > > @@driver.customWebServiceCall > > > > > > > > -- > > Ola Bini ( http://ola-bini.blogspot.com) > > JvYAML, RbYAML, JRuby and Jatha contributor > > System Developer, Karolinska Institutet (http://www.ki.se) > > OLogix Consulting ( http://www.ologix.com) > > > > "Yields falsehood when quined" yields falsehood when quined. > > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >I have put the similar code in my ApplicationController .... here is the code class ApplicationController < ActionController::Base require ''soap/wsdlDriver'' factory = SOAP::WSDLDriverFactory.new(TRANSIDIOM_WSDL_URL) @@soap = factory.create_rpc_driver @@soap.wiredump_file_base="#{RAILS_ROOT}/log/transidiom.log" def ......my actions.... I am in Development environment and the problem is that @@soap which should be initialized only once (at class instantiation time) is initialized on every request (I checkd the object_id and they are different on each request). Being a newbie my guess is that atleast in development env there is a new instance of the controller created on every request. So my question is in Production env is there only one instance of the controller to serve all requests or is there a new instance of controller created on every request? thanks in advance -daya -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060807/2a1b1957/attachment.html
Ola Bini
2006-Aug-07 17:22 UTC
[Rails] Store SOAP::RPC::Driver in user session throws TypeError
linux user wrote:> Ola, this is a Good idea but can it give rise race conditions?? or are > there anyother implications which might be painful to debug/fix in the > long run?Not that I know of. And there''s no race condition involved if you don''t have any trouble with having more than one reference to the Driver floating around, which shouldn''t be a problem. -- Ola Bini (http://ola-bini.blogspot.com) JvYAML, RbYAML, JRuby and Jatha contributor System Developer, Karolinska Institutet (http://www.ki.se) OLogix Consulting (http://www.ologix.com) "Yields falsehood when quined" yields falsehood when quined.
linux user
2006-Aug-08 13:54 UTC
[Rails] Store SOAP::RPC::Driver in user session throws TypeError
I know it is very difficult to simulate and identify a race condition. But this is what I think may happen if I use class variable or even global variable to store SOAP::RPC::Driver object. In production each controller is loaded only once which I assume means there is only one instance of controller serving multiple requests. Now lets assume that all the parameters needed to make the web service call are local to the action (method), which means these parameters are immune from race conditions since the are on the thread stack and each thread is unique for each request. But the class variable or global variable is shared across multiple requests, now imagine the same class variable or global variable accessed in different controllers or different actions of same controller. Hence there is a potential that the result of a webservice call may get mixed up, depending on who gets the returned value first. I may completely wrong here since I don''t know about the inner working of the CGI/FCGI/Rails request handling. Can anyone please enlighten me or tell me if my fears are misplaced? TIA -daya On 8/7/06, Ola Bini <ola.bini@ki.se> wrote:> > linux user wrote: > > Ola, this is a Good idea but can it give rise race conditions?? or are > > there anyother implications which might be painful to debug/fix in the > > long run? > > Not that I know of. And there''s no race condition involved if you don''t > have any trouble with having more than one reference to the Driver > floating around, which shouldn''t be a problem. > > -- > Ola Bini (http://ola-bini.blogspot.com) > JvYAML, RbYAML, JRuby and Jatha contributor > System Developer, Karolinska Institutet (http://www.ki.se) > OLogix Consulting (http://www.ologix.com) > > "Yields falsehood when quined" yields falsehood when quined. > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060808/169089c9/attachment.html