Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

cschwier/RestTemplate-vs-WebClient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RestTemplate-vs-WebClient

Simple project to show the difference in memory usage of Springs RestTemplate and WebClient APIs for this stackoverflow question.

Experiment

  1. Start the DemoServer, DemoRestTemplate and DemoWebClient applications.
  2. Start jconsole -interval=1 and attach to both client applications.
  3. Perform a GC on both clients.
  4. Type the absolute path to a file (in this case 550MB) in the client CLIs and press Enter.
  5. Wait a couple of seconds and perform a GC for the DemoRestTemplate application.

Observation

For some reason the RestTemplate uses an excessive amount of memory (take the differently scaled y-axis into account) and creates a lot of garbage in the old generation.

memory usage graph

  1. The initial manual GC
  2. The request
  3. The manual GC

Hypothesis

It looks like the RestTemplate creates multiple copies of the complete file (memory usage is roughly 5x file size) while the WebClient creates just some helper objects and a buffer which it frees correctly after use.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages