From e7874eee91c05dad3082ae67feebf4065e7e736d Mon Sep 17 00:00:00 2001 From: Xavier Fernandez Date: Wed, 29 Jan 2020 21:48:52 +0100 Subject: [PATCH] Use mmap.PAGESIZE constant as value for first read. This size can have a real impact on performance when a lot of files need to be read. The performance relies heavily on the file system cache so reading as little pages as possible helps a lot on memory constrained systems. Signed-off-by: Xavier Fernandez --- prometheus_client/mmap_dict.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prometheus_client/mmap_dict.py b/prometheus_client/mmap_dict.py index 274b7389..28d4ab82 100644 --- a/prometheus_client/mmap_dict.py +++ b/prometheus_client/mmap_dict.py @@ -83,7 +83,7 @@ def read_all_values_from_file(filename): with open(filename, 'rb') as infp: # Read the first block of data, including the first 4 bytes which tell us # how much of the file (which is preallocated to _INITIAL_MMAP_SIZE bytes) is occupied. - data = infp.read(65535) + data = infp.read(mmap.PAGESIZE) used = _unpack_integer(data, 0)[0] if used > len(data): # Then read in the rest, if needed. data += infp.read(used - len(data))