Web API vs ServiceStack

In this blog post I will examine the claim made in a twit by Anil Mujagić. The claim is that ServiceStack is 3 times faster than Web Api. It is backed by test project https://github.com/anilmujagic/ServiceBenchmark. These are the results of that test:

WebApi vs ServiceStack

As you can see ServiceStack appears to be 3 times faster than Web API. But one aspect of the test is very strange. It uses different clients for each service. The ServiceStack client is used as it was supposed to be used, but the WebApi is used with HttpClient that for some reason is not within async method but calls Result of a task twise per call. This is known to be a very bad practice. Let's try the test so we use the same ServiceStack client for both services. If the test is testing the clients, then it is not using properly HttpClient, so I assume it is testing the services. I branched the project here https://github.com/vbodurov/ServiceBenchmark. Master branch is the original test, and modified branch is with only change of both using the same ServiceStack client. The results are as follow:

WebApi vs ServiceStack

This is already far away from 3:1 advantage mentioned before. But we still see a smaller up to 10% advantage for ServiceStack. Does that mean that ServiceStack after all is faster? I will try to convince you that this is not the case.

Another problem with this test is that the requests are emitted one after another, in a sequence. In the real world the new request will not wait for the old one to finish. I changed the tests so they run request simultaneously. I also changed services to call a third service that sleeps the thread for 100 ms. Web API uses async await pattern for that, ServiceStack 3.9.* does not support async await so it uses synchronous call. In the real world this can be call to internal API, database or file system. These are the differences. And the branch is modified-with-client-async-await. The results are as follow:

WebApi vs ServiceStack

Now you can clearly see it in favor of Web API. We see that each separate call in ServiceStack might be up to 10% faster because of more optimal serialization. But when there is sufficient number of simultaneous requests, the throughput of Web API is much better, because of unblocking nature of the async await pattern.

In this example I only review the free ServiceStack version 3.9. I know that the paid version 4+ supports async await, but it is costly. Potentially there is a way to modify 3.9 so it uses async await, but I am not sure of the implications of that so it is not discussed here.

Summary: Web API with non blocking async await calls has a higher throughput of requests, compared to the free version of ServiceStack 3.9.

Share this post:   digg     Stumble Upon     del.icio.us     E-mail

zhesse
Posted on 2/4/2015 12:34:44 PM

Hello,

Your "3d star visualizer" no longer works on my Chrome 64-bit browser, running the correct version of Silverlight. This was a wonderful tool and I very much enjoyed using it, yet I can no longer access it. Why is this?

Vladimir Bodurov
Posted on 2/4/2015 2:39:50 PM

Hi Zhesse,

I just tried http://www.bodurov.com/NearestStars/ and this http://www.bodurov.com/VectorVisualizer/ with C:\Program Files (x86)\Google\Chrome\Application\chrome.exe and it works, this looks like a 32 bit though. Do you mean Chrome beta? https://www.google.com/chrome/browser/beta.html

Commenting temporarily disabled