0

im using spring MVC and webflow to create a game server and serve some web pages to the users. Thing is, the javascript game will also make multiple ajax calls to restful services on the same server for some game logic. While the web page serving performance is not critical, the restful service calls need to be as efficient as possible (efficient as in response time).

For performance of the services, would it be better to use pure JAX-RS (jersey) web service calls without the spring ws overhead (since i understand the spring layer could affect performances negatively) or would it be the same if i used the spring webservices framework instead and maintain integration with the rest of the spring family?

thanks!

JayDee
  • 949
  • 1
  • 13
  • 20

2 Answers2

8

There aren't many clear benchmarks out there, but take a look here: http://www.techempower.com/benchmarks/

It clearly shows the overhead of using Spring. Compared to Servlets that serve JSON manually Spring is "slower". Personally, I don't think that Spring cuts development time, unless you are very much familiar with it. Creating a simple servlet that will act as a REST API is very simple. Take a look at the servlet code from the benchmark: Servlet benchmark

user2502475
  • 159
  • 2
  • 8
  • Yes, writing Servlet that acts as a REST API is simple. But think about all the boilerplate code you will end up if your API grows, difficult to maintain difficult to unit test. Think what you will face when trying to add a security layer, dependency injection, multiple mediatypes, async requests... All those abstractions are already solved with frameworks like Spring MVC REST, Jersey, DropWizard, REST Easy, etc. You can easily add or remove what you need or not like Lego pieces. You can always fine tune your application and improve performance instead of prematurely thinking on it. – raspacorp Oct 08 '15 at 05:30
4

I don't think Spring per se will affect performance negatively. Where did you hear that?

Spring web services are "contract first" SOAP services. If you're saying that you don't want to pay the overhead of SOAP, XML, marshalling and unmarshalling, then you have a valid point. That's true whether you use Spring to implement the services or not.

REST is HTTP, so it's a natural for AJAX calls.

I believe Spring 3.0 supports REST, so it's not a "Spring or not Spring" choice:

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/new-in-3.html#d0e1188

duffymo
  • 305,152
  • 44
  • 369
  • 561
  • but are spring REST services slower than pure JAX-RS ones? (is there a lot of spring overhead?) – JayDee May 13 '12 at 01:40
  • 1
    No, I don't believe so. I would say that you should not optimize prematurely. Implement something and get some data about it. If the performance is unacceptable, profile the code to find out where it's slow and fix it. Repeat until performance is acceptable. The functionality you add to the services is more likely to be the performance bottleneck than Spring. They write better code than you or me. – duffymo May 13 '12 at 01:58
  • 1
    Incorrect answer. See http://www.techempower.com/benchmarks/#section=data-r9&hw=peak&test=json – stepanian Aug 01 '14 at 03:11