Skip to content

High memory use and possible leak with sequential access mode #268

Open
@mzur

Description

@mzur

Hi, first of all thank you @jcupitt for this library and your incredible support!

I ran across an issue where sequential access mode seems to consume a lot more memory and also seems to have a leak where memory is not freed after processing, comapred to random mode. Here is a minimal example script:

<?php

include 'vendor/autoload.php';

use Jcupitt\Vips\Image;

$access = 'sequential';
// $access = 'random';

for ($i=0; $i < 10; $i++) {
    $image = Image::newFromFile('my_image.jpg', ['access' => $access]);
    $width = $image->width;
    $height = $image->height;

    $buf = $image->crop(round($width / 2) - 150, round($height / 2) - 150, 300, 300)
        ->writeToBuffer('.jpg');
}

When I use sequential mode and call /usr/bin/time -v php my_script.php I get:

	Command being timed: "php my_script.php"
	User time (seconds): 13.18
	System time (seconds): 5.63
	Percent of CPU this job got: 99%
	Elapsed (wall clock) time (h:mm:ss or m:ss): 0:18.82
	Average shared text size (kbytes): 0
	Average unshared data size (kbytes): 0
	Average stack size (kbytes): 0
	Average total size (kbytes): 0
	Maximum resident set size (kbytes): 15905256
	Average resident set size (kbytes): 0
	Major (requiring I/O) page faults: 0
	Minor (reclaiming a frame) page faults: 4083940
	Voluntary context switches: 852
	Involuntary context switches: 672
	Swaps: 0
	File system inputs: 0
	File system outputs: 0
	Socket messages sent: 0
	Socket messages received: 0
	Signals delivered: 0
	Page size (bytes): 4096
	Exit status: 0

So it uses 15 GB to process the images. When I increase the number of iterations in the loop, the consumed memory also increases.

With random mode I get:

	Command being timed: "php my_script.php"
	User time (seconds): 5.20
	System time (seconds): 4.96
	Percent of CPU this job got: 181%
	Elapsed (wall clock) time (h:mm:ss or m:ss): 0:05.61
	Average shared text size (kbytes): 0
	Average unshared data size (kbytes): 0
	Average stack size (kbytes): 0
	Average total size (kbytes): 0
	Maximum resident set size (kbytes): 472804
	Average resident set size (kbytes): 0
	Major (requiring I/O) page faults: 0
	Minor (reclaiming a frame) page faults: 107770
	Voluntary context switches: 7281
	Involuntary context switches: 1091
	Swaps: 0
	File system inputs: 0
	File system outputs: 12657432
	Socket messages sent: 0
	Socket messages received: 0
	Signals delivered: 0
	Page size (bytes): 4096
	Exit status: 0

It is faster and only uses 500 MB.

The image I use is a heavily compressed JPEG (~60 MB):

$ vipsheader my_image.jpg
my_image.jpg: 46789x46169 uchar, 3 bands, srgb, jpegload

I can share the actual file via email but not publicly here.

I use vips-8.15.1 and jcupitt/vips:2.4.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions