Feign Calls Pegged the CPU: Repeated HttpMessageConverter Initialization
A record of one application incident: analysis, investigation, resolution.
A CPU alert came in and the business team reported that API responses were taking too long. This post records the entire process — from the alert, through diagnosis, to root cause analysis — ending at a CPU saturation problem caused by Feign calls.
🕰️ Version note: this post was written in 2024, on a stack of Feign 10.1.0, Spring 5.1.6, Java 8 (1.8.0_242). The ecosystem moves fast; read it against the versions you actually use.
Background
On the morning of the 9th, a CPU alert came in; at the same time, the business team reported that upstream services depending on this one were seeing very slow API responses.
1 | Application alert - CPU usage change |
Traffic
Peak QPS per instance was around 100.
Why care about QPS? Because 100 QPS shouldn't consume this much CPU — and the request and response bodies were small.


POD monitoring
POD quotas:
- CPU request 2 cores, CPU limit 3 cores
- Memory request 7 GiB, memory limit 9 GiB



From the charts:
- CPU load stayed high;
- TCP connections and thread count climbed steeply starting at 11:40.
ARMS
Looking at the trace monitoring, we saw that the time was going into the customer service calling external APIs via Feign.

Interim mitigation
Scale out instances and increase the CPU allocation.
Root cause analysis
The investigation of the third-party APIs and the open-platform gateway is omitted here; the conclusion was that neither the third-party APIs nor the open-platform gateway had a problem.
They were checked first because the trace showed the time going into calls to third-party APIs.

From the ARMS chart:
- CPU time was concentrated in the Decoder and Encoder of the Feign calls;
- The Decoder/Encoder time was concentrated in:
HttpMessageConverters#getDefaultConverters()=>WebMvcConfigurationSupport#addDefaultHttpMessageConverters=>- ......(full call chain in the excerpt below)
1 | feign.ReflectiveFeign$BuildTemplateByResolvingArgs.create(Object[]) (14.37%, 1.43 minutes) |
Custom Encoder and Decoder
Encoder
Look at the Encoder in com.jiankunking.common.core.feign.FeignClientsConfig:
1 | public Encoder feignEncoder() { |
Decoder
Look at the Decoder in com.jiankunking.common.core.feign.FeignClientsConfig:
1 | public Decoder feignDecoder() { |
A quick search for 'spring feign encode jackson cpu usage high'
=> https://segmentfault.com/a/1190000043037032
=> https://mp.weixin.qq.com/s/RuqltkN9VdVQ1K3GKuJ-Gw
=> https://meantobe.github.io/2019/12/21/ClassLoader/
Source analysis
Look at the code around registerWellKnownModulesIfAvailable:
1 |
|
The logic is: if Joda-Time's LocalDate is on the classpath, load Jackson's corresponding JodaModule (via the LaunchedURLClassLoader).
Why didn't I suspect jdk8ModuleClass and javaTimeModuleClass? Because the common package already depends on these two artifacts:
1 | compile "com.fasterxml.jackson.datatype:jackson-datatype-jdk8:${v.jacksonDatatype}" |
That made the fix clear.
Solutions
Avoid repeated ClassLoader loading
Add this dependency to the project. After it loads once, later calls can retrieve it via findLoadedClass, reducing the resource cost of class loading.
1 | <dependency> |
Avoid re-initializing HttpMessageConverters
1 | public Decoder feignDecoder() { |
Note that this approach breaks Feign calls whose return value is a simple type — for example, a String return throws:
1 | feign.codec.DecodeException: Error while extracting response for type [class java.lang.String] and content type [application/json]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token |
A further refinement:
1 | List<HttpMessageConverter<?>> decodeMessageConverters = new ArrayList<>(); |
Results after the fix
CPU usage dropped by half

Summary
When you customize Feign's codecs with SpringEncoder / SpringDecoder, avoid re-initializing HttpMessageConverters on every call. If you don't need the default HttpMessageConverters, pass false as the first argument when constructing HttpMessageConverters, so the defaults are never initialized.
This article is the English edition of a post originally published in Chinese.