Skip to content

Commit

Permalink
Use mmap.PAGESIZE constant as value for first read.
Browse files Browse the repository at this point in the history
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 <xavier.fernandez@polyconseil.fr>
  • Loading branch information
xavfernandez committed Jan 30, 2020
1 parent 470b2d3 commit e7874ee
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion prometheus_client/mmap_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit e7874ee

Please sign in to comment.