From 16d14c8688fb6d09760001777d9bf0548b454633 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Mon, 12 Dec 2022 11:54:23 -0500 Subject: [PATCH 01/15] A minimal upload/download script. --- benchmarks/test_immutable.py | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 benchmarks/test_immutable.py diff --git a/benchmarks/test_immutable.py b/benchmarks/test_immutable.py new file mode 100644 index 000000000..15ba0cb4f --- /dev/null +++ b/benchmarks/test_immutable.py @@ -0,0 +1,47 @@ +""" +First attempt at benchmarking immutable uploads and downloads. + +TODO Parameterization (pytest?) +- Foolscap vs not foolscap +- Number of nodes +- Data size +- Number of needed/happy/total shares. +""" + +from twisted.trial.unittest import TestCase + +from allmydata.util.deferredutil import async_to_deferred +from allmydata.util.consumer import MemoryConsumer +from allmydata.test.common_system import SystemTestMixin +from allmydata.immutable.upload import Data as UData + + +class ImmutableBenchmarks(SystemTestMixin, TestCase): + """Benchmarks for immutables.""" + + FORCE_FOOLSCAP_FOR_STORAGE = True + + @async_to_deferred + async def test_upload_and_download(self): + self.basedir = self.mktemp() + + DATA = b"Some data to upload\n" * 2000 + + # 3 nodes + await self.set_up_nodes(3) + + # 3 shares + for c in self.clients: + c.encoding_params["k"] = 3 + c.encoding_params["happy"] = 3 + c.encoding_params["n"] = 3 + + # 1. Upload: + uploader = self.clients[0].getServiceNamed("uploader") + results = await uploader.upload(UData(DATA, convergence=None)) + + # 2. Download: + uri = results.get_uri() + node = self.clients[1].create_node_from_uri(uri) + mc = await node.read(MemoryConsumer(), 0, None) + self.assertEqual(b"".join(mc.chunks), DATA) From a3e02f14c93f5e532f15b9c9c1ed20a516f2ac9d Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Mon, 12 Dec 2022 13:38:25 -0500 Subject: [PATCH 02/15] Add a little timing. --- benchmarks/test_immutable.py | 37 +++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/benchmarks/test_immutable.py b/benchmarks/test_immutable.py index 15ba0cb4f..abf4bddf3 100644 --- a/benchmarks/test_immutable.py +++ b/benchmarks/test_immutable.py @@ -8,6 +8,9 @@ TODO Parameterization (pytest?) - Number of needed/happy/total shares. """ +from time import time +from contextlib import contextmanager + from twisted.trial.unittest import TestCase from allmydata.util.deferredutil import async_to_deferred @@ -16,16 +19,25 @@ from allmydata.test.common_system import SystemTestMixin from allmydata.immutable.upload import Data as UData +@contextmanager +def timeit(name): + start = time() + try: + yield + finally: + print(f"{name}: {time() - start:.3f}") + + class ImmutableBenchmarks(SystemTestMixin, TestCase): """Benchmarks for immutables.""" - FORCE_FOOLSCAP_FOR_STORAGE = True + FORCE_FOOLSCAP_FOR_STORAGE = False @async_to_deferred async def test_upload_and_download(self): self.basedir = self.mktemp() - - DATA = b"Some data to upload\n" * 2000 + + DATA = b"Some data to upload\n" * 10 # 3 nodes await self.set_up_nodes(3) @@ -36,12 +48,15 @@ class ImmutableBenchmarks(SystemTestMixin, TestCase): c.encoding_params["happy"] = 3 c.encoding_params["n"] = 3 - # 1. Upload: - uploader = self.clients[0].getServiceNamed("uploader") - results = await uploader.upload(UData(DATA, convergence=None)) + for i in range(5): + # 1. Upload: + with timeit("upload"): + uploader = self.clients[0].getServiceNamed("uploader") + results = await uploader.upload(UData(DATA, convergence=None)) - # 2. Download: - uri = results.get_uri() - node = self.clients[1].create_node_from_uri(uri) - mc = await node.read(MemoryConsumer(), 0, None) - self.assertEqual(b"".join(mc.chunks), DATA) + # 2. Download: + with timeit("download"): + uri = results.get_uri() + node = self.clients[1].create_node_from_uri(uri) + mc = await node.read(MemoryConsumer(), 0, None) + self.assertEqual(b"".join(mc.chunks), DATA) From 5266adefce55b3ac565fe20e1c9b1e46d99ad76c Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Tue, 13 Dec 2022 10:57:07 -0500 Subject: [PATCH 03/15] Include CPU time. --- benchmarks/test_immutable.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/benchmarks/test_immutable.py b/benchmarks/test_immutable.py index abf4bddf3..abdd11035 100644 --- a/benchmarks/test_immutable.py +++ b/benchmarks/test_immutable.py @@ -8,7 +8,7 @@ TODO Parameterization (pytest?) - Number of needed/happy/total shares. """ -from time import time +from time import time, process_time from contextlib import contextmanager from twisted.trial.unittest import TestCase @@ -22,10 +22,11 @@ from allmydata.immutable.upload import Data as UData @contextmanager def timeit(name): start = time() + start_cpu = process_time() try: yield finally: - print(f"{name}: {time() - start:.3f}") + print(f"{name}: {time() - start:.3f} elapsed, {process_time() - start_cpu:.3f} CPU") class ImmutableBenchmarks(SystemTestMixin, TestCase): From edb2a2120439106502ff43a004b22afbfe4e207f Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 14 Dec 2022 11:18:17 -0500 Subject: [PATCH 04/15] For now, just one share. Plus more docs. --- benchmarks/test_immutable.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/benchmarks/test_immutable.py b/benchmarks/test_immutable.py index abdd11035..2098030a8 100644 --- a/benchmarks/test_immutable.py +++ b/benchmarks/test_immutable.py @@ -1,5 +1,5 @@ """ -First attempt at benchmarking immutable uploads and downloads. +First attempt at benchmarking uploads and downloads. TODO Parameterization (pytest?) - Foolscap vs not foolscap @@ -32,22 +32,24 @@ def timeit(name): class ImmutableBenchmarks(SystemTestMixin, TestCase): """Benchmarks for immutables.""" + # To use HTTP, change to true: FORCE_FOOLSCAP_FOR_STORAGE = False @async_to_deferred - async def test_upload_and_download(self): + async def test_upload_and_download_immutables(self): self.basedir = self.mktemp() + # To test larger files, change this: DATA = b"Some data to upload\n" * 10 - # 3 nodes - await self.set_up_nodes(3) + # 1 node + await self.set_up_nodes(1) - # 3 shares + # 1 share for c in self.clients: - c.encoding_params["k"] = 3 - c.encoding_params["happy"] = 3 - c.encoding_params["n"] = 3 + c.encoding_params["k"] = 1 + c.encoding_params["happy"] = 1 + c.encoding_params["n"] = 1 for i in range(5): # 1. Upload: From 983521c17ad9c3926cd48f6d92dfc7240a9e75cb Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 14 Dec 2022 11:22:05 -0500 Subject: [PATCH 05/15] Mutable benchmark. --- benchmarks/test_immutable.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/benchmarks/test_immutable.py b/benchmarks/test_immutable.py index 2098030a8..ea7624fcc 100644 --- a/benchmarks/test_immutable.py +++ b/benchmarks/test_immutable.py @@ -17,6 +17,7 @@ from allmydata.util.deferredutil import async_to_deferred from allmydata.util.consumer import MemoryConsumer from allmydata.test.common_system import SystemTestMixin from allmydata.immutable.upload import Data as UData +from allmydata.mutable.publish import MutableData @contextmanager @@ -36,7 +37,7 @@ class ImmutableBenchmarks(SystemTestMixin, TestCase): FORCE_FOOLSCAP_FOR_STORAGE = False @async_to_deferred - async def test_upload_and_download_immutables(self): + async def test_upload_and_download_immutable(self): self.basedir = self.mktemp() # To test larger files, change this: @@ -63,3 +64,30 @@ class ImmutableBenchmarks(SystemTestMixin, TestCase): node = self.clients[1].create_node_from_uri(uri) mc = await node.read(MemoryConsumer(), 0, None) self.assertEqual(b"".join(mc.chunks), DATA) + + + @async_to_deferred + async def test_upload_and_download_mutable(self): + self.basedir = self.mktemp() + + # To test larger files, change this: + DATA = b"Some data to upload\n" * 10 + + # 1 node + await self.set_up_nodes(1) + + # 1 share + for c in self.clients: + c.encoding_params["k"] = 1 + c.encoding_params["happy"] = 1 + c.encoding_params["n"] = 1 + + for i in range(5): + # 1. Upload: + with timeit("upload"): + result = await self.clients[0].create_mutable_file(MutableData(DATA)) + + # 2. Download: + with timeit("download"): + data = await result.download_best_version() + self.assertEqual(b"".join(mc.chunks), DATA) From 954ae2f2a4dc2dede706cdb1277803f80d51607b Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 14 Dec 2022 11:23:06 -0500 Subject: [PATCH 06/15] Make tests pass again. --- benchmarks/test_immutable.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/benchmarks/test_immutable.py b/benchmarks/test_immutable.py index ea7624fcc..7268b3399 100644 --- a/benchmarks/test_immutable.py +++ b/benchmarks/test_immutable.py @@ -43,8 +43,8 @@ class ImmutableBenchmarks(SystemTestMixin, TestCase): # To test larger files, change this: DATA = b"Some data to upload\n" * 10 - # 1 node - await self.set_up_nodes(1) + # 2 nodes + await self.set_up_nodes(2) # 1 share for c in self.clients: @@ -90,4 +90,4 @@ class ImmutableBenchmarks(SystemTestMixin, TestCase): # 2. Download: with timeit("download"): data = await result.download_best_version() - self.assertEqual(b"".join(mc.chunks), DATA) + self.assertEqual(data, DATA) From 146341de59654fd066f0eb2a6d455ebd6bc442d7 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 14 Dec 2022 11:24:47 -0500 Subject: [PATCH 07/15] Rename. --- benchmarks/{test_immutable.py => upload_download.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename benchmarks/{test_immutable.py => upload_download.py} (100%) diff --git a/benchmarks/test_immutable.py b/benchmarks/upload_download.py similarity index 100% rename from benchmarks/test_immutable.py rename to benchmarks/upload_download.py From 1d6a4e6d562cac42016475235daccee08677350c Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 14 Dec 2022 11:43:59 -0500 Subject: [PATCH 08/15] Minor cleanups. --- benchmarks/upload_download.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/benchmarks/upload_download.py b/benchmarks/upload_download.py index 7268b3399..11da26624 100644 --- a/benchmarks/upload_download.py +++ b/benchmarks/upload_download.py @@ -10,6 +10,10 @@ TODO Parameterization (pytest?) from time import time, process_time from contextlib import contextmanager +from tempfile import mkdtemp +import os + +import pytest from twisted.trial.unittest import TestCase @@ -27,7 +31,9 @@ def timeit(name): try: yield finally: - print(f"{name}: {time() - start:.3f} elapsed, {process_time() - start_cpu:.3f} CPU") + print( + f"{name}: {time() - start:.3f} elapsed, {process_time() - start_cpu:.3f} CPU" + ) class ImmutableBenchmarks(SystemTestMixin, TestCase): @@ -37,11 +43,9 @@ class ImmutableBenchmarks(SystemTestMixin, TestCase): FORCE_FOOLSCAP_FOR_STORAGE = False @async_to_deferred - async def test_upload_and_download_immutable(self): - self.basedir = self.mktemp() - - # To test larger files, change this: - DATA = b"Some data to upload\n" * 10 + async def setUp(self): + SystemTestMixin.setUp(self) + self.basedir = os.path.join(mkdtemp(), "nodes") # 2 nodes await self.set_up_nodes(2) @@ -52,6 +56,11 @@ class ImmutableBenchmarks(SystemTestMixin, TestCase): c.encoding_params["happy"] = 1 c.encoding_params["n"] = 1 + @async_to_deferred + async def test_upload_and_download_immutable(self): + # To test larger files, change this: + DATA = b"Some data to upload\n" * 10 + for i in range(5): # 1. Upload: with timeit("upload"): @@ -65,11 +74,8 @@ class ImmutableBenchmarks(SystemTestMixin, TestCase): mc = await node.read(MemoryConsumer(), 0, None) self.assertEqual(b"".join(mc.chunks), DATA) - @async_to_deferred async def test_upload_and_download_mutable(self): - self.basedir = self.mktemp() - # To test larger files, change this: DATA = b"Some data to upload\n" * 10 From d3e89cc8fdd63472fa3b273b04998a2be48547d6 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 14 Dec 2022 11:44:17 -0500 Subject: [PATCH 09/15] Add print(). --- benchmarks/upload_download.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/benchmarks/upload_download.py b/benchmarks/upload_download.py index 11da26624..053aa6955 100644 --- a/benchmarks/upload_download.py +++ b/benchmarks/upload_download.py @@ -56,6 +56,8 @@ class ImmutableBenchmarks(SystemTestMixin, TestCase): c.encoding_params["happy"] = 1 c.encoding_params["n"] = 1 + print() + @async_to_deferred async def test_upload_and_download_immutable(self): # To test larger files, change this: From 9e06cc09d800521d1abf9a0120115c0c24ec5c90 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 14 Dec 2022 11:45:32 -0500 Subject: [PATCH 10/15] Make it line up. --- benchmarks/upload_download.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/benchmarks/upload_download.py b/benchmarks/upload_download.py index 053aa6955..bf0f95838 100644 --- a/benchmarks/upload_download.py +++ b/benchmarks/upload_download.py @@ -65,7 +65,7 @@ class ImmutableBenchmarks(SystemTestMixin, TestCase): for i in range(5): # 1. Upload: - with timeit("upload"): + with timeit(" upload"): uploader = self.clients[0].getServiceNamed("uploader") results = await uploader.upload(UData(DATA, convergence=None)) @@ -92,7 +92,7 @@ class ImmutableBenchmarks(SystemTestMixin, TestCase): for i in range(5): # 1. Upload: - with timeit("upload"): + with timeit(" upload"): result = await self.clients[0].create_mutable_file(MutableData(DATA)) # 2. Download: From 55c1bae13e93c25f9a455667b18e71921ce31d74 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 14 Dec 2022 11:45:56 -0500 Subject: [PATCH 11/15] Instructions. --- benchmarks/upload_download.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/benchmarks/upload_download.py b/benchmarks/upload_download.py index bf0f95838..14447b550 100644 --- a/benchmarks/upload_download.py +++ b/benchmarks/upload_download.py @@ -1,6 +1,10 @@ """ First attempt at benchmarking uploads and downloads. +To run: + +$ pytest benchmarks/upload_download.py -s -v -Wignore + TODO Parameterization (pytest?) - Foolscap vs not foolscap - Number of nodes From f22988e9df21909bc612d2df6b8d28515166145c Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 14 Dec 2022 11:46:01 -0500 Subject: [PATCH 12/15] Unused. --- benchmarks/upload_download.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/benchmarks/upload_download.py b/benchmarks/upload_download.py index 14447b550..1ea015aeb 100644 --- a/benchmarks/upload_download.py +++ b/benchmarks/upload_download.py @@ -17,8 +17,6 @@ from contextlib import contextmanager from tempfile import mkdtemp import os -import pytest - from twisted.trial.unittest import TestCase from allmydata.util.deferredutil import async_to_deferred From 4cc4670e0545840e07317b2487ac461443fa0f7d Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 14 Dec 2022 11:46:30 -0500 Subject: [PATCH 13/15] Correct docs. --- benchmarks/upload_download.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/upload_download.py b/benchmarks/upload_download.py index 1ea015aeb..2690a89e2 100644 --- a/benchmarks/upload_download.py +++ b/benchmarks/upload_download.py @@ -41,7 +41,7 @@ def timeit(name): class ImmutableBenchmarks(SystemTestMixin, TestCase): """Benchmarks for immutables.""" - # To use HTTP, change to true: + # To use Foolscap, change to True: FORCE_FOOLSCAP_FOR_STORAGE = False @async_to_deferred From 46954613dcb3e382f43233c3c7f2e6def2cffcbf Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 14 Dec 2022 11:48:36 -0500 Subject: [PATCH 14/15] Don't need setup. --- benchmarks/upload_download.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/benchmarks/upload_download.py b/benchmarks/upload_download.py index 2690a89e2..bd1b08e7a 100644 --- a/benchmarks/upload_download.py +++ b/benchmarks/upload_download.py @@ -83,15 +83,6 @@ class ImmutableBenchmarks(SystemTestMixin, TestCase): # To test larger files, change this: DATA = b"Some data to upload\n" * 10 - # 1 node - await self.set_up_nodes(1) - - # 1 share - for c in self.clients: - c.encoding_params["k"] = 1 - c.encoding_params["happy"] = 1 - c.encoding_params["n"] = 1 - for i in range(5): # 1. Upload: with timeit(" upload"): From 0ce7331c2118a6c92f25dee33e960303ff08b34e Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 14 Dec 2022 11:56:35 -0500 Subject: [PATCH 15/15] News file. --- newsfragments/3952.minor | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 newsfragments/3952.minor diff --git a/newsfragments/3952.minor b/newsfragments/3952.minor new file mode 100644 index 000000000..e69de29bb