[Solved] io.Copy is very slow when run inside a kubernetes pod

Eshan Asks: io.Copy is very slow when run inside a kubernetes pod
my go code downloads a file from Azure and writes it to the disk. For a file size of about 512 Mega Bytes, the code takes around a min to download and write the file to disk (when executed standalone).

For the same code executed as a container inside kubernetes pod, the time shoots up to almost 3 min. I added additional traces in the code to figure out that it is the io.Copy function which takes the maximum time. I do have cpu and memory quota limitation set on the pod and performance does improve on increasing the same. But just want to understand/get some guidance if there is an even efficient way to do it?

Solutions tried: Tried io.CopyBuffer but didn’t help much.

Would really appreciate some guidance if someone else has faced a similar issue.

Code:
resp, err := client.Do(req)
    err != nil { 
        return err
    }
    if resp.StatusCode != 200 {
        buf := new(bytes.Buffer)
        _, _ = buf.ReadFrom(resp.Body)
        return errors.New(string(buf.Bytes()))
    }
    err = os.Mkdir(outputPath+"/"+digest[7:], 0700)
    if err != nil {
        return err
    }
    filepath := outputPath + "/" + digest[7:] + "/layer.tar.gzip"
    file, err := os.OpenFile(filepath, os.O_RDWR|os.O_CREATE, 0600)
    if err != nil {
        return err
    }
    _, err = io.Copy(file, resp.Body)
    if err != nil {
        _ = file.Close()
        return err
    }
    _ = file.Close()

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.