Skip to content

Commit aef00f6

Browse files
redboTarmac
authored andcommitted
change chunks_per_sync config to mb_per_sync
2 parents 21d6ad4 + 76ce08f commit aef00f6

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

etc/object-server.conf-sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ use = egg:swift#object
2323
# disk_chunk_size = 65536
2424
# max_upload_time = 86400
2525
# slow = 1
26+
# on PUTs, sync data every n MB
27+
# mb_per_sync = 512
2628

2729
[object-replicator]
2830
# log_name = object-replicator

swift/obj/server.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def __init__(self, conf):
259259
self.log_requests = conf.get('log_requests', 't')[:1].lower() == 't'
260260
self.max_upload_time = int(conf.get('max_upload_time', 86400))
261261
self.slow = int(conf.get('slow', 0))
262-
self.chunks_per_sync = int(conf.get('chunks_per_sync', 8000))
262+
self.bytes_per_sync = int(conf.get('mb_per_sync', 512)) * 1024 * 1024
263263

264264
def container_update(self, op, account, container, obj, headers_in,
265265
headers_out, objdevice):
@@ -359,11 +359,10 @@ def PUT(self, request):
359359
upload_expiration = time.time() + self.max_upload_time
360360
etag = md5()
361361
upload_size = 0
362+
last_sync = 0
362363
with file.mkstemp() as (fd, tmppath):
363364
if 'content-length' in request.headers:
364365
fallocate(fd, int(request.headers['content-length']))
365-
chunk_count = 0
366-
dropped_cache = 0
367366
for chunk in iter(lambda: request.body_file.read(
368367
self.network_chunk_size), ''):
369368
upload_size += len(chunk)
@@ -373,13 +372,11 @@ def PUT(self, request):
373372
while chunk:
374373
written = os.write(fd, chunk)
375374
chunk = chunk[written:]
376-
chunk_count += 1
377375
# For large files sync every 512MB (by default) written
378-
if chunk_count % self.chunks_per_sync == 0:
376+
if upload_size - last_sync >= self.bytes_per_sync:
379377
os.fdatasync(fd)
380-
drop_buffer_cache(fd, dropped_cache,
381-
upload_size - dropped_cache)
382-
dropped_cache = upload_size
378+
drop_buffer_cache(fd, last_sync, upload_size - last_sync)
379+
last_sync = upload_size
383380

384381
if 'content-length' in request.headers and \
385382
int(request.headers['content-length']) != upload_size:

test/unit/obj/test_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def setUp(self):
5656
mkdirs(os.path.join(self.testdir, 'sda1', 'tmp'))
5757
conf = {'devices': self.testdir, 'mount_check': 'false'}
5858
self.object_controller = object_server.ObjectController(conf)
59-
self.object_controller.chunks_per_sync = 1
59+
self.object_controller.bytes_per_sync = 1
6060

6161
def tearDown(self):
6262
""" Tear down for testing swift.object_server.ObjectController """

0 commit comments

Comments
 (0)