JD ([info]ratsoprizo) wrote,

The Hunt for Red October^W^W ActionWebService

We are looking at possibly doing a SOAP API based on Rails, PHP, or the elusive ???, and it all depends on speed. We figure that one of the largest hang-ups would be parsing the XML. So yesterday, I started hunting through ActionWebService trying to answer the following: just how quickly can ruby parse SOAP requests?

I first found myself in the ActionWebService source code, where I quickly discovered that there were lots of SOAP::* calls, meaning ActionWebService uses the SOAP module that is in the Ruby standard library.

So, into the SOAP source code - let's look at SOAP::Parser. Right off the top we find it includes xsd/xmlparser, and it looks likes the SOAP parser is set up with an event-handler parser - which is certainly a good sign. So let's look at XSD::XMLParser, where things get interesting.

Finally, in xsd/xmlparser.rb we find this:

# Try to load XML processor.
loaded = false
[
  'xsd/xmlparser/xmlscanner',
  'xsd/xmlparser/xmlparser',
  'xsd/xmlparser/rexmlparser',
].each do |lib|
  begin
    require lib
    loaded = true
    break
  rescue LoadError
  end
end
unless loaded
  raise RuntimeError.new("XML processor module not found.")
end

Thus, Ruby will use three different libraries, in order: xmlscan, XMLParser, and REXML. I had already been investigating XML parsers, but had not heard of xmlscan. Well, xmlscan is The fastest XML parser written in 100% pure Ruby. Odd, I think: why not prefer XMLParser, the expat-based library, over a Ruby-based one? Must be faster, right? Let's find out.

If you download xmlscan you find it includes a file samples/xmlbench.rb - a simple benchmarking program. If you run it with a bunch of libraries installed, it gives you results. How novel! I ran it against a 280kb XML file:

$ ruby samples/xmlbench.rb ../test.xml
                                    user     system      total        real
** File **
XMLScan::XMLScanner             0.390000   0.040000   0.430000 (  0.429473)
XMLScan::XMLParser              0.440000   0.030000   0.470000 (  0.473714)
XMLScan::XMLNamespace           0.490000   0.060000   0.550000 (  0.549025)
XMLScan::REXML                  0.940000   0.120000   1.060000 (  1.053696)
REXML::Document.parse_stream    0.810000   0.120000   0.930000 (  0.925994)
REXML::Document.new             1.280000   0.130000   1.410000 (  1.414166)
XMLParser                       0.040000   0.010000   0.050000 (  0.036426)

Well, it seems XMLParser knocked the socks off the competition. Tell me then, why would the XSD parser use xmlscan over XMLParser? I am not sure. But it looks like I will be uninstalling xmlscan to make sure to maximize SOAP performance.


  • Post a new comment

    Error

    Your IP address will be recorded 

  • 5 comments

[info]waloeiii

November 16 2005, 23:25:25 UTC 6 years ago

REST > SOAP

If you don't absolutly need something that SOAP can provide, I'd suggest a REST implementation. Easier to work with. eBay and Amazon both offer both methods, and both report that REST usage is upwards of 75% of all their web services activity. Simplicity!

[info]waloeiii

November 16 2005, 23:26:39 UTC 6 years ago

Re: REST > SOAP

Of course if this is going to be used only internally, do whatever you want!

[info]ratsoprizo

November 17 2005, 04:06:43 UTC 6 years ago

ActionWebService > REST

SOAP and XML-RPC is implemented by ActionWebService. These are, really, the big reasons to look at it. The only reason why SOAP is so great is because there are many libraries which create a very nice API to it - the idea being that you don't have to parse or create XML yourself.

XML-RPC is essentially structured REST. REST is pretty lame - it's like: look, you can do XML feeds, and XML via POST, and call it a web service. I am not a big SOAP fan, and generally like XML-RPC better since it's so much simpler. Doing something REST-like is actually fairly compelling, as it removes having any XML-RPC limitations. But, it means rolling your own from start to finish, and the whole point of moving towards something like SOAP or XML-RPC is to give developers the ability to use pre-existing libraries. I am hoping that XML-RPC is a viable option for those who desire a simpler interface to the system.

Granted: I knew very little to nothing about SOAP, XML-RPC, or REST before Monday, so this has been quite a rush. More thoughts are welcome. :)

[info]waloeiii

November 17 2005, 06:52:40 UTC 6 years ago

Re: ActionWebService > REST

I agree with your saying that REST is pretty simple, what I was referring to mostly is the complexity of SOAP. SOAP adds a whole layer of complexity that you don't always need, its great when you do but its using a sword when a knife will do fine and be easier to move (god I've been playing too much WoW).

[info]ratsoprizo

November 18 2005, 00:41:56 UTC 6 years ago

Best of all Worlds

We are probably supporting all of them: XML-RPC and SOAP will come with ActionWebService. We may then extend AWS to do REST as well; hopefully we can even contribute that back to Rails. We believe having a "Plain Old XML" interface that is both extremely easy to generate as well as parse by hand will be a benefit to many.
Create an Account
Forgot your login or password?
Facebook Twitter More login options
English • Español • Deutsch • Русский…