Open rvishrm opened 1 year ago
Hi, the following code is a simplified version of my code. Here, I'm trying to do some image processing on the image buffer.
package main import "github.com/h2non/bimg" func resizeAndConvertImage(image []byte, height int, width int) ([]byte, error) { size, err := bimg.NewImage(image).Size() if err != nil { return nil, err } if width == 0 && height == 0 { width = size.Width height = size.Height } options := bimg.Options{ Width: width, Height: height, } imgType := bimg.JPEG image, _ = bimg.NewImage(image).Process(options) image, _ = bimg.NewImage(image).Convert(imgType) return image, err } func main() { newImage, err := resizeAndConvertImage(imageBuffer, height, width) }
I used a script for hitting so many requests to the server.
I started the script at 11:31 and stopped it at 11:38. It can be clearly seen that around 2GB of memory is stucked somewhere.
Then I tried commenting Process() and Convert() functions one by one.
// image, _ = bimg.NewImage(image).Process(options)
// image, _ = bimg.NewImage(image).Convert(imgType)
And graph showed around 1GB of memory leakage. (script start time is 11:53)
Then I commented both the function calls.
// image, _ = bimg.NewImage(image).Process(options) // image, _ = bimg.NewImage(image).Convert(imgType)
And the memory graph shows that there is no memory leakage. Memory used is just in MBs.
Am I missing something obvious here?
I have also tried following options for the fix
os.Setenv("GODEBUG", "madvdontneed=1") bimg.VipsCacheSetMax(0) bimg.VipsCacheSetMaxMem(0) os.Setenv("MALLOC_ARENA_MAX", "2")
Facing the same issue in process and convert function.
have you tried setting MALLOC_ARENA_MAX=2 ?
MALLOC_ARENA_MAX=2
Any solution for this?
Hi, the following code is a simplified version of my code. Here, I'm trying to do some image processing on the image buffer.
I used a script for hitting so many requests to the server.
I started the script at 11:31 and stopped it at 11:38. It can be clearly seen that around 2GB of memory is stucked somewhere.
Then I tried commenting Process() and Convert() functions one by one.
And graph showed around 1GB of memory leakage. (script start time is 11:53)
Then I commented both the function calls.
And the memory graph shows that there is no memory leakage. Memory used is just in MBs.
Am I missing something obvious here?
I have also tried following options for the fix