Thumbs: Allow more fine-grained control over libvips memory usage #2308

Open
opened 2026-02-20 01:09:28 -05:00 by deekerman · 0 comments
Owner

Originally created by @lastzero on GitHub (Apr 25, 2025).

Originally assigned to: @lastzero on GitHub.

As an admin, I would like to have more control over the memory usage of libvips so that I can adjust it as needed, e.g. when running multiple instances on the same server.

Our primary thumbnail image generation library libvips is initialized in internal/thumb/vips_init.go using the following parameters:

// vipsConfig provides the config for initializing libvips.
func vipsConfig() *vips.Config {
	return &vips.Config{
		MaxCacheMem:      MaxCacheMem,
		MaxCacheSize:     MaxCacheSize,
		MaxCacheFiles:    MaxCacheFiles,
		ConcurrencyLevel: NumWorkers,
		ReportLeaks:      false,
		CacheTrace:       false,
		CollectStats:     false,
	}
}

Currently, memory usage parameters like MaxCacheMem are automatically set depending on the available system memory, see internal/thumb/init.go:

const (
	DefaultCacheMem   = 128 * MiB
	DefaultCacheSize  = 128
	DefaultCacheFiles = 16
	DefaultWorkers    = 1
)

// Set the maximum amount of cached data allowed
// before libvips drops cached operations.
switch {
case availableMemory >= 4*GiB:
	MaxCacheMem = 512 * MiB
case availableMemory >= 1*GiB:
	MaxCacheMem = 256 * MiB
case availableMemory <= 0:
	// Use default if free memory could not be detected.
	MaxCacheMem = DefaultCacheMem
default:
	// Reduce cache size and number of workers if the system seems low on memory.
	MaxCacheMem = 64 * MiB
	maxWorkers = 1
}

This should be improved to allow admins or orchestration tools to set a static cache size limit as needed, e.g. to limit total memory usage when running multiple instances / indexing multiple libraries on the same server.

Related Issues:

Originally created by @lastzero on GitHub (Apr 25, 2025). Originally assigned to: @lastzero on GitHub. **As an admin, I would like to have more control over the memory usage of libvips so that I can adjust it as needed, e.g. when [running multiple instances](https://github.com/photoprism/photoprism/issues/98) on the same server.** Our primary thumbnail image generation library `libvips` is initialized in `internal/thumb/vips_init.go` using the following parameters: ```go // vipsConfig provides the config for initializing libvips. func vipsConfig() *vips.Config { return &vips.Config{ MaxCacheMem: MaxCacheMem, MaxCacheSize: MaxCacheSize, MaxCacheFiles: MaxCacheFiles, ConcurrencyLevel: NumWorkers, ReportLeaks: false, CacheTrace: false, CollectStats: false, } } ``` Currently, memory usage parameters like `MaxCacheMem` are automatically set depending on the available system memory, see `internal/thumb/init.go`: ```go const ( DefaultCacheMem = 128 * MiB DefaultCacheSize = 128 DefaultCacheFiles = 16 DefaultWorkers = 1 ) // Set the maximum amount of cached data allowed // before libvips drops cached operations. switch { case availableMemory >= 4*GiB: MaxCacheMem = 512 * MiB case availableMemory >= 1*GiB: MaxCacheMem = 256 * MiB case availableMemory <= 0: // Use default if free memory could not be detected. MaxCacheMem = DefaultCacheMem default: // Reduce cache size and number of workers if the system seems low on memory. MaxCacheMem = 64 * MiB maxWorkers = 1 } ``` This should be improved to allow admins or orchestration tools to set a *static* cache size limit as needed, e.g. to limit *total* memory usage when running multiple instances / indexing multiple libraries on the *same* server. **Related Issues:** - https://github.com/photoprism/photoprism/issues/98
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/photoprism#2308
No description provided.