mirror of
https://github.com/pgsty/minio.git
synced 2026-10-09 11:15:57 +03:00
caching: Optimize memory allocations. (#3405)
This change brings in changes at multiple places - Reuse buffers at almost all locations ranging from rpc, fs, xl, checksum etc. - Change caching behavior to disable itself under low memory conditions i.e < 8GB of RAM. - Only objects cached are of size 1/10th the size of the cache for example if 4GB is the cache size the maximum object size which will be cached is going to be 400MB. This change is an optimization to cache more objects rather than few larger objects. - If object cache is enabled default GC percent has been reduced to 20% in lieu with newly found behavior of GC. If the cache utilization reaches 75% of the maximum value GC percent is reduced to 10% to make GC more aggressive. - Do not use *bytes.Buffer* due to its growth requirements. For every allocation *bytes.Buffer* allocates an additional buffer for its internal purposes. This is undesirable for us, so implemented a new cappedWriter which is capped to a desired size, beyond this all writes rejected. Possible fix for #3403.
This commit is contained in:
@@ -18,6 +18,8 @@
|
||||
|
||||
package cmd
|
||||
|
||||
import "github.com/minio/minio/pkg/sys"
|
||||
|
||||
func setMaxOpenFiles() error {
|
||||
// Golang uses Win32 file API (CreateFile, WriteFile, ReadFile,
|
||||
// CloseHandle, etc.), then you don't have a limit on open files
|
||||
@@ -26,6 +28,15 @@ func setMaxOpenFiles() error {
|
||||
}
|
||||
|
||||
func setMaxMemory() error {
|
||||
// TODO: explore if Win32 API's provide anything special here.
|
||||
// Make sure globalMaxCacheSize is less than RAM size.
|
||||
stats, err := sys.GetStats()
|
||||
if err != nil && err != sys.ErrNotImplemented {
|
||||
return err
|
||||
}
|
||||
// If TotalRAM is <= minRAMSize we proceed to enable cache.
|
||||
// cache is always 50% of the totalRAM.
|
||||
if err == nil && stats.TotalRAM >= minRAMSize {
|
||||
globalMaxCacheSize = uint64(float64(50*stats.TotalRAM) / 100)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user