The modern way to handle this is with GOMEMLIMIT
https://tip.golang.org/doc/gc-guide

- sean

On Mon, Feb 12, 2024 at 8:33 PM Mike Mitchell
<mikemitchellweb...@gmail.com> wrote:
>
> Purely for the sake of experiment (this is not a production environment 
> thing), I have tried to test out the Heap Ballast technique of reducing the 
> number of garbage collections with a small heap size, which I read about in a 
> blog post by Twitch, and I think I must have misinterpreted the use case of 
> such a technique. Can anyone help clarify for me? Thank you in advance
>
> My program consists of a webserver in the main func
>
>  http.ListenAndServe(":6000", http.DefaultServeMux)
>
> and I create a small ballast on my Digital Ocean 1 GB ram droplet (the twitch 
> blog post said they made a ballast of 10 <<30) but I did 10 << 20
>
>  ballast := make([]byte, 10<<20)
>
> I then sent a million requests to it
>
> ab -k -c 8 -n 1000000 "http://127.0.0.1:6000/";
>
> I also did the same without the heap ballast.
>
> The results (see attached images) surprised me because there was basically 
> the same number of garbage collections with and without the ballast. The only 
> difference the ballast seems to have made was that it increased HeapIdle 
> enormously.  How do people use Heap Ballast to reduce the number of GCs?
>
>  go version go1.21.1 linux/amd64
>
> I have read many people referring to this Heap Ballast technique as a way to 
> reduce the number of garbage collections with a small heap size. In fact, 
> this is what it says in the Twitch article
>
> At steady state, our application was triggering ~8–10 garbage collection (GC) 
> cycles a second (400–600 per minute).
>
> 30% of CPU cycles were being spent in function calls related to GC
>
> During traffic spikes the number of GC cycles would increase
>
> Our heap size on average was fairly small (<450Mib)
>
> At steady state, our application was triggering ~8–10 garbage collection (GC) 
> cycles a second (400–600 per minute).
>
> 30% of CPU cycles were being spent in function calls related to GC
>
> During traffic spikes the number of GC cycles would increase
>
> Our heap size on average was fairly small (<450Mib)
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/7cee5b4e-24cc-4579-b5c9-62b93298c931n%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAGabyPpEHMKkOPC-5C_BiaUA2o4x%2BOq8wKz4QkbjqDNVUS2Avg%40mail.gmail.com.

Reply via email to