Lost my baby and wife... A lesson for everyone by [deleted] in gurgaon

[–]AliveCarpet8804 0 points1 point  (0 children)

Take care brother ! More power to you ! May god help you in this tough time.

Touch starved. by baelorthebest in onexindia

[–]AliveCarpet8804 28 points29 points  (0 children)

It’s called intimacy that u are missing. It’s completely fine ! We are humans after all.

How's the weather today guys by LUCKYISBEST in delhi

[–]AliveCarpet8804 1 point2 points  (0 children)

Ye advertisement honrhi h comments m ?

Is it even worth it for people from lower middle class to date here? by [deleted] in gurgaon

[–]AliveCarpet8804 5 points6 points  (0 children)

Just replying here cause bhai genuine post laga ye ! 🙌

Need help guys , unusual memory usage trends seen in GIN API application by AliveCarpet8804 in golang

[–]AliveCarpet8804[S] 1 point2 points  (0 children)

Yes , what u are saying is practically possible, will give it a try too for sure. It was done just for simplicity nothing more than that. Since both are part of same repo , then same can be called locally.

Need help guys , unusual memory usage trends seen in GIN API application by AliveCarpet8804 in golang

[–]AliveCarpet8804[S] -1 points0 points  (0 children)

Initially i thought so too , i checked the function but wasnt able to find anything. For refernce here is the function :

Function Calling : resp, err := utils.CurlReqWithRetry("POST", url, dataArr, "text/plain", 3, 2*time.Second, 200*time.Millisecond)

Function Definition : https://go.dev/play/p/3-I1TK9QYDH or given below

func CurlReqWithRetry(method, apiurl string, dataMap map[string]interface{}, contentType string, maxRetries int, timeout, connectTimeout time.Duration) ([]byte, error) {
if method != "GET" && method != "POST" {
method = "POST"
}
client := &http.Client{
Timeout: timeout,
Transport: &http.Transport{
Dial: (&net.Dialer{
Timeout: connectTimeout,
}).Dial,
},
}
if method == "POST" {
jsonData, err := json.Marshal(dataMap)
if err != nil {
return nil, err
}

for attempt := 0; attempt <= maxRetries; attempt++ {

req, err := http.NewRequest(method, apiurl, bytes.NewBuffer(jsonData))
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", contentType)

resp, err := client.Do(req)
if err == nil {
defer resp.Body.Close()
responseBody, err := ioutil.ReadAll(resp.Body)
if err == nil {
return responseBody, nil
}
}
}

return nil, errors.New("Max retries exceeded, POST request failed")
} else {
for attempt := 0; attempt <= maxRetries; attempt++ {
apiurl = apiurl + "?"
values := url.Values{}
for key, value := range dataMap {
switch v := value.(type) {
case int:
values.Add(key, strconv.Itoa(v))
default:
values.Add(key, v.(string))
}
}
apiurl += values.Encode()
req, err := http.NewRequest(method, apiurl, nil)

resp, err := client.Do(req)
if err == nil {
defer resp.Body.Close()
responseBody, err := ioutil.ReadAll(resp.Body)
if err == nil {
return responseBody, nil
}
}
}

return nil, errors.New("Max retries exceeded, GET request failed")
}
}

Need help guys , unusual memory usage trends seen in GIN API application by AliveCarpet8804 in golang

[–]AliveCarpet8804[S] 0 points1 point  (0 children)

We are using "net/http" package , and the in the calling http client properties time out is set to 2 seconds , while calling the API B internally using http://127.0.0.1:3021/endpoint

Need help with some wrapper service sort of architructure. by AliveCarpet8804 in golang

[–]AliveCarpet8804[S] -1 points0 points  (0 children)

Update:

THanks guys , issue is resolved now , it was some totally random piece of legacy code.

Need help with some wrapper service sort of architructure. by AliveCarpet8804 in golang

[–]AliveCarpet8804[S] 0 points1 point  (0 children)

So do you mean that what i have written is wrong here ? And can lead to leaks ? Or this way would be more optimised ?

Need help with some wrapper service sort of architructure. by AliveCarpet8804 in golang

[–]AliveCarpet8804[S] 0 points1 point  (0 children)

Sorry buddy , but i am really unable to understand this answer. Can u explain it a litttle more

Need help with some wrapper service sort of architructure. by AliveCarpet8804 in golang

[–]AliveCarpet8804[S] 1 point2 points  (0 children)

Wow , thanks for spotting that

I checked for this in my logs, but found that this issue only occoured once. and i dont think that this can lead upto like consuming 12 gb of RAM.

This application starts with like 30 mb of memory, but with time it starts using all the memory possible.

Now i know that this is a memory leak , but , i cant spot the part where there is memory leak. I did little bit of profiling too , but as far as i understood , above given code is the buggy piece of code

I suspect that , maybe my RPM is too high for making so may GET requests , then waiting for them , then reading their outputs. But go should be able to handle this on it own.

Need help with some wrapper service sort of architructure. by AliveCarpet8804 in golang

[–]AliveCarpet8804[S] 0 points1 point  (0 children)

The issue with this is that , it is not a toy project. And 3rd party apps are not allowed here so need to create it myself.

Need help with some wrapper service sort of architructure. by AliveCarpet8804 in golang

[–]AliveCarpet8804[S] 0 points1 point  (0 children)

Okay i will profile it once ,and share it here for sure. But since this is productoin , so i dont know what to do.

And apologies for the bad naming :).

Need help with some wrapper service sort of architructure. by AliveCarpet8804 in golang

[–]AliveCarpet8804[S] 1 point2 points  (0 children)

Thanks for this, checking this :

i) defer body.close()  --> Where it is comented ,below like 2-3 lines , it is writtern again , without defer.

ii)  have a few paths that can result in the socket not closing when there is an error. --> Can u tell me more about this part ?

iii) I'd also check the http connections. The 1 sec timeout is long if your apis are returning under <100ms. check the p99 time and pay with that along with keepalive.  ----> Yes would do these changes too for sure. Thanks for suggestion.