tahoe-lafs/benchmarks/upload_download.py

95 lines
2.6 KiB
Python
Raw Normal View History

2022-12-12 16:54:23 +00:00
"""
First attempt at benchmarking uploads and downloads.
2022-12-12 16:54:23 +00:00
2022-12-14 16:45:56 +00:00
To run:
$ pytest benchmarks/upload_download.py -s -v -Wignore
2022-12-12 16:54:23 +00:00
TODO Parameterization (pytest?)
- Foolscap vs not foolscap
- Number of nodes
- Data size
- Number of needed/happy/total shares.
"""
2022-12-13 15:57:07 +00:00
from time import time, process_time
2022-12-12 18:38:25 +00:00
from contextlib import contextmanager
2022-12-14 16:43:59 +00:00
from tempfile import mkdtemp
import os
2022-12-12 16:54:23 +00:00
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
2022-12-14 16:22:05 +00:00
from allmydata.mutable.publish import MutableData
2022-12-12 16:54:23 +00:00
2022-12-12 18:38:25 +00:00
@contextmanager
def timeit(name):
start = time()
2022-12-13 15:57:07 +00:00
start_cpu = process_time()
2022-12-12 18:38:25 +00:00
try:
yield
finally:
2022-12-14 16:43:59 +00:00
print(
f"{name}: {time() - start:.3f} elapsed, {process_time() - start_cpu:.3f} CPU"
)
2022-12-12 18:38:25 +00:00
2022-12-12 16:54:23 +00:00
class ImmutableBenchmarks(SystemTestMixin, TestCase):
"""Benchmarks for immutables."""
2022-12-14 16:46:30 +00:00
# To use Foolscap, change to True:
2022-12-12 18:38:25 +00:00
FORCE_FOOLSCAP_FOR_STORAGE = False
2022-12-12 16:54:23 +00:00
@async_to_deferred
2022-12-14 16:43:59 +00:00
async def setUp(self):
SystemTestMixin.setUp(self)
self.basedir = os.path.join(mkdtemp(), "nodes")
2022-12-12 16:54:23 +00:00
2022-12-14 16:23:06 +00:00
# 2 nodes
await self.set_up_nodes(2)
2022-12-12 16:54:23 +00:00
# 1 share
2022-12-12 16:54:23 +00:00
for c in self.clients:
c.encoding_params["k"] = 1
c.encoding_params["happy"] = 1
c.encoding_params["n"] = 1
2022-12-12 16:54:23 +00:00
2022-12-14 16:44:17 +00:00
print()
2022-12-14 16:43:59 +00:00
@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
2022-12-12 18:38:25 +00:00
for i in range(5):
# 1. Upload:
2022-12-14 16:45:32 +00:00
with timeit(" upload"):
2022-12-12 18:38:25 +00:00
uploader = self.clients[0].getServiceNamed("uploader")
results = await uploader.upload(UData(DATA, convergence=None))
# 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)
2022-12-14 16:22:05 +00:00
@async_to_deferred
async def test_upload_and_download_mutable(self):
# To test larger files, change this:
DATA = b"Some data to upload\n" * 10
for i in range(5):
# 1. Upload:
2022-12-14 16:45:32 +00:00
with timeit(" upload"):
2022-12-14 16:22:05 +00:00
result = await self.clients[0].create_mutable_file(MutableData(DATA))
# 2. Download:
with timeit("download"):
data = await result.download_best_version()
2022-12-14 16:23:06 +00:00
self.assertEqual(data, DATA)