Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8728505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:39:28+00:00 2026-06-13T08:39:28+00:00

I’ve a springRest web service endpoint that returns a string text of size 4MB.

  • 0

I’ve a springRest web service endpoint that returns a string text of size 4MB. As we do load test of this endpoint we constantly see heap spikes and ultimately the system crashes. I’m thinking – as we make requests each request is serviced by a thread separately. My hypothesis is: Because the string is saved in a global static variable, each thread takes a copy of the 4MB and after around 3000 requests the heap is all consumed and the system crashes because 3000 threads taking each 4MB is around 12GB and hence the system goes out of memory. But this is my hypothesis.

My question: doesn’t tomcat reclaim the memory after each thread that processes a request has done it’s job?
Is this related to GC (garbage collection)?
In the request life cycle – as a request comes, a thread is created (per that request) does the thread get it’s own copy of the response or it just references the response? if that huge string response is copied to each thread then may be that’s why the heap spike is showing.
When the response is given back to the client how does tomcat reclaim the resources of that thread? when does it do it? is claiming request threads related to GC?

Another aspect that i observed is: delay on the method socketWrite0() – this takes from 70-95% of the response time. It is a bottle neck i think. So in the flow of request response – who writes to the socket? the thread? or the thread hands the response to tomcat and tomcat writes it?

If any of you could give me a hint or an aspect to look at that relates memory spikes with huge string responses, i’d really appreciate it. thanks guys!

rose

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:39:29+00:00Added an answer on June 13, 2026 at 8:39 am

    Thanks guys for the comments given.
    The problem was very cryptic because it comes only when the system is stressed with multiple users on performance test. We tried different changes to cache client, caching strategies and cache time to live, connection time out.

    We tried changing the algorithm. Caching more data to avoid expensive calls to legacy systems.

    We tried changing the data structure from JSONArray to String.

    All didn’t help!!

    Finally we figured out it was the load balancer that was creating the issue. We disabled it and it all worked fine.

    If i’m given a chance to say one thing: performance/scalability of an enterprise system is bottle necked by the less performant component, so do a careful empirical testing and attack the problem after spending time figuring out the correct pain point. DO NOT RUN TO CHANGE YOUR CODE.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
I have a reasonable size flat file database of text documents mostly saved in
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.