Skip to content

Commit 8228ddb

Browse files
nathanchrsveluca93
authored andcommitted
Increase file cache chunk size from 16 KB to 1 MB
To improve performance when connecting to worker instances over high latency network
1 parent 05a3b8d commit 8228ddb

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

cms/db/filecacher.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,7 @@ class FileCacher:
478478
"""
479479

480480
# This value is very arbitrary, and in this case we want it to be a
481-
# one-size-fits-all, since we use it for many conversions. It has
482-
# been chosen arbitrarily based on performance tests on my machine.
481+
# one-size-fits-all, since we use it for many conversions.
483482
# A few consideration on the value it could assume follow:
484483
# - The page size of large objects is LOBLKSIZE, which is BLCKSZ/4
485484
# (BLCKSZ is the block size of the PostgreSQL database, which is
@@ -489,7 +488,8 @@ class FileCacher:
489488
# - The `io' module defines a DEFAULT_BUFFER_SIZE constant, whose
490489
# value is 8192.
491490
# CHUNK_SIZE should be a multiple of these values.
492-
CHUNK_SIZE = 16 * 1024 # 16 KiB
491+
# Note that a too-small value can cause issues on high-latency networks.
492+
CHUNK_SIZE = 1024 * 1024 # 1 MiB
493493
backend: FileCacherBackend
494494

495495
def __init__(self, service: "Service | None" = None, path: str | None = None, null: bool = False):

cmstestsuite/unit_tests/server/file_middleware_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class TestFileByDigestMiddleware(unittest.TestCase):
3636
def setUp(self):
3737
# Choose a size that is larger than FileCacher.CHUNK_SIZE.
3838
self.content = \
39-
bytes(random.getrandbits(8) for _ in range(17 * 1024))
39+
bytes(random.getrandbits(8) for _ in range(1024 * 1024 + 128))
4040
self.digest = bytes_digest(self.content)
4141

4242
self.filename = "foobar.pdf"

0 commit comments

Comments
 (0)