I am using Spring Boot 1.5.8 and spring-web 4.3.12. I have noticed that, when I make a request for data from one of our REST endpoints, more time is spent on data serialization than the rest of the operation. I have been looking into strategies to speed things up, and I learned about the Jackson Afterburner module. The spring documentation claims that I only need to create a #Bean in a #Configuration class and the ObjectMapper that is created will have that module registered. Unfortunately, after adding the Spring bean, the serialization performance remains unchanged. What am I doing wrong?
Also, if anyone has any other ideas about how to increase the json serialization performance in a Spring REST controller, I would be very interested in hearing about them.
Thanks in advance.
I have tried the Afterburner module, and I did not notice much (or really any) improvement in performance. Maybe Spring is already using it, or other, optimizations. After looking around a bit, I learned about Kryo, and that seems to help.
If nobody else posts a suggestion, I will have to accept my own answer, but I will wait for a bit.
Related
Does anyone know hot to use Apache AVRO RPC with Spring boot? Every single AVRO implementation I have seen is hosted on a netty server.
You might be trying to achieve the same thing I'm trying to achieve -- speeding up json serialization with spring boot and spring web. Or maybe you just want to use avro? And my comment is a little late, since it's months after you posted. I have run across this information about using an avro message converter, so thought I would share it with you to see if it helps:
https://docs.spring.io/spring-cloud-stream/docs/Brooklyn.RELEASE/reference/html/contenttypemanagement.html#_schema_based_message_converters
Or did you already find it? If so, can you share whatever solution that you came up with? Our rest json serialization takes much longer than the whole rest of the operation and I would like to speed it up as much as possible.
We are analyzing different concepts for one of my projects. We decided to use Spring Boot & Microservices architecture.
After further discussions, we came to a query whether we CAN/SHOULD use Spring AOP to resolve cross cutting concerns of various microservices?
If not how can we address common concerns of microservices like logging, transaction mgmt, etc?
I have googled this topic extensively (even went to 5 pages for same search), but no luck. Any help appreciated.
Use Spring interceptors. They have interceptors and factories for just about anything. Lets you add instrumentation and common code to all aspects.
UPDATE: samples interceptors and factories.
ClientHttpRequestInterceptor
FilterRegistrationBean
SimpleClientHttpRequestFactory
ChannelInterceptor
I don't think that there is anything to worry about using AOP. This is how Spring does things usually under the hood.
I'd just be careful with logging method invocations, especially parameters which is the common use (abuse) of AOP.
Ususally the less code you write the better. If you can use standard, proven way of doing things - use it.
What are the different ways to resolve UI messages and provide internalization support in an web application using spring framework?
We use property files and ResourceBundleMessageSource to resolve messages in Spring. Spring's implementation causes an high cpu usage in our application. There are two problems with ResourceBundleMessageSource implementation.
Locking contention - getResourceBundle() and getMessageFormat() are both synchronized.
MissingResourceException - Resolving a message involves looping through all the resource bundles defined in the application and calling bundle.getString(key). bundle.getString(key) method call throws an MissingResourceException if the key is not found. Searching for the key until we find the message for the given key. Since exception construction is a slow process and could eat up the CPU (which is what I observed in our load tests) this looks like a bottleneck.
Though there are workarounds for both of the above problems (by extending the class and overridding the behavior) I wanted to know if there are other ways in spring framework to provide internationalization support to a web application.
Thanks in advance
You can use the ReloadableResourceBundleMessageSource instead. It provides some internal caching.
If that does not work, I would advise implementing your own MessageSource (It's fairly straight forward). Spring provides AbstractMessageSource which may be helpful to start with.
From there, you can implement some caching. More than likely, your localizations are not being updated frequently.
You can read here on using the new Cacheable annotations in Spring 3.1
spring 3.1 #Cacheable example
I have done this already with success in applications that allow admins to override locales in the database. Your particular implementation however would obviously be very different.
Spring is a popular framework, however I have difficulties to see in which situation the framework would actually help.
Currently I'm using the following:
* Tomcat
* Jersey
* Jackson
* Hibernate
Together this results in a Webservice, created by annotations, automatic JSON (un)marshalling and a comfortable Object/Relational Mapping.
So honestly at the moment I'm not missing anything, but I might just not know what great thing I'm missing... Could you help me out with this?
Thank you
Spring is a big framework providing a lot of functionality. It's hard to talk about advantages without knowing what functionality are you trying to use in the project.
Most probably you talk about Spring as an IoC container. It is very important part of Spring, but there is also AOP, transaction management, JDBC abstraction layer, authentication and authorization, testing and some more.
In a nutshell, Spring offers you uniform way to control dependencies between your objects. This is called inversion of control or dependency injection. Using it you can create pluggable, testable code that is easy to maintain.
In addition it gives you gazillion utility classes that just make life easier. For example, Hibernate is much easier to maintain via Spring facilities. It kind of brings together many different technologies under the same roof.
I'd like to learn Spring MVC framework basis.
My personal experience tells clearly that more than reading manuals, docs, howtos only is only one important part of self-training, but to capitalize real experience you need to solve real problems.
May someone suggest a fake-project that I can implement in my free-time, avoiding only-theoretical approaches and at the same time watch at the main issues of Spring programming?
Does a NerdDinner.com-like free-chapter somewhere exists for Spring?
You could go through each of the Spring samples, and attempt to recreate them on your own.
I have found that a very effective method for learning Spring is to go on the Spring JIRA and solve a bug. It forces you to get down and dirty in the code, and you get to see what's really going on behind the scenes.