Giter Club home page Giter Club logo

Comments (6)

DarthSim avatar DarthSim commented on May 22, 2024

That's, actually, not totally correct. libvips does use your drive space to store decoded images that are too big to be securely stored in RAM. As you noticed correctly, 7360*4912*3 ≈ 104 MB, and many popular image processing tools like ImageMagick would store this amount of data on the drive.
Anyway, libvips removes all unneeded decoded data, so it won't eat all your space.

If you allow processing such big images on the fly, you should know the cost of it. They will either use a lot of your memory or drive space.

from imgproxy.

homm avatar homm commented on May 22, 2024

This makes sense, but there are some problems:

  1. Those files are deleted from the file system after request, but as you can see from lsof output, they are still opened by the imgproxy process and that is why OS can't free this space. So yes, during my tests imgproxy actually ate 4.8G of free space and left 0 bytes.

  2. Disk storage is very-very slow compared to memory even with SSD. There are already limits for maximum image resolution, so imgproxy shouldn't use more memory than defined by those limits. There are no reasons to store any data on the disk if it fits into memory. And if the data doesn't fit, OS already has mechanisms to use disk storage if necessary: swap.

  3. If this storage should prevent from high memory usage, why after the end of the short benchmark (ab -c 10 -n 50, all requests are finished) imgproxy consumes 13% (0.94Gb) of memory?

screen shot 2017-09-28 at 13 50 53

from imgproxy.

DarthSim avatar DarthSim commented on May 22, 2024
  1. It seems like libvips reuses temporary files, I don;t see any other explanation of this behavior for now. I'll continue digging into it.
    Anyway, I made some changes in imgproxy, and now it uses sequential access mode instead of random access in most cases. The sequential mode doesn't create a temporary file and saves some memory. The only problem is that sequential mode isn't compatible with smartcrop, so I have to use random access mode with it.

  2. Disk storage is slow, for sure. But RAM is a more valuable thing. There are a lot of reasons to not use all the memory we have. There may be other processes that need RAM. Or there may be RAM limits for the process, and it'll be killed instead of swapping. So it's not such a bad idea to use your disk instead of eating all the memory. Sure, wasting the disk with temp files isn't nice, but again, if you allow processing such big files on the fly, there will be consequences.
    If you still want to use your memory, you can set env variable VIPS_DISC_THRESHOLD=1000MB, to libvips won't save images of less than 1000 Mb decompressed size to disk.

  3. imgproxy and vips still need memory to download and process files. The garbage collector in Go doesn't instantly return memory to the operating system, it uses allocated memory for the new objects. I made some optimizations and enforced GC to return memory more often. Now it looks much better to me.

Btw, could you share the image which you use for testing?

from imgproxy.

homm avatar homm commented on May 22, 2024

Btw, could you share the image which you use for testing?

Sure, here it is: https://en.wikipedia.org/wiki/File:0000140_Wat_Arun_01.jpg

from imgproxy.

homm avatar homm commented on May 22, 2024

Results with the current master:

  • No disk swapping
  • ≈400% CPU load during the test (unlike the previous version with only ≈150% CPU load).
  • 2 times more throughput
  • only 320 megabytes memory usage after the same test

So, everything is definitely much better )

from imgproxy.

DarthSim avatar DarthSim commented on May 22, 2024

Nice, thanks for testing!

from imgproxy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.