-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce memory usage for chunk_hashes
On a 180MB file this reduced total memory usage by approximately 40%. This was also marginally faster (but not by much). I've also added the start of unittests for the writer module, and I've written some very basic unittests for the chunk_hashes function.
- Loading branch information
Showing
2 changed files
with
37 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from hashlib import sha256 | ||
|
||
from tests.unit import unittest | ||
import mock | ||
|
||
from boto.glacier.writer import Writer, chunk_hashes | ||
|
||
|
||
class TestChunking(unittest.TestCase): | ||
def test_chunk_hashes_exact(self): | ||
chunks = chunk_hashes('a' * (2 * 1024 * 1024)) | ||
self.assertEqual(len(chunks), 2) | ||
self.assertEqual(chunks[0], sha256('a' * 1024 * 1024).digest()) | ||
|
||
def test_chunks_with_leftovers(self): | ||
bytestring = 'a' * (2 * 1024 * 1024 + 20) | ||
chunks = chunk_hashes(bytestring) | ||
self.assertEqual(len(chunks), 3) | ||
self.assertEqual(chunks[0], sha256('a' * 1024 * 1024).digest()) | ||
self.assertEqual(chunks[1], sha256('a' * 1024 * 1024).digest()) | ||
self.assertEqual(chunks[2], sha256('a' * 20).digest()) | ||
|
||
def test_less_than_one_chunk(self): | ||
chunks = chunk_hashes('aaaa') | ||
self.assertEqual(len(chunks), 1) | ||
self.assertEqual(chunks[0], sha256('aaaa').digest()) |