Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
  • Loading branch information
bigcat88 committed Jul 15, 2023
1 parent 0dab020 commit 65fc062
Show file tree
Hide file tree
Showing 15 changed files with 309 additions and 201 deletions.
45 changes: 33 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,36 @@ help:
@echo " html make HTML docs"
@echo " "
@echo " Next commands are only for dev environment with nextcloud-docker-dev!"
@echo " register register nc_py_api in host as an application(requires activated venv)"
@echo " this should run from the host you are developing on, not in a container with Nextcloud"
@echo " and only last Nextcloud version(28) is supported, for other versions tests runs on GitHub"
@echo " tests run nc_py_api tests to check that registration was successful"

.PHONY: register
register:
/bin/sh scripts/dev_register.sh

.PHONY: tests
tests:
python3 -m pytest
@echo " They should run from the host you are developing on(with activated venv) and not in the container with Nextcloud!"
@echo " "
@echo " register28 register nc_py_api for Nextcloud 28"
@echo " register27 register nc_py_api for Nextcloud 27"
@echo " register26 register nc_py_api for Nextcloud 26"
@echo " "
@echo " tests28 run nc_py_api tests for Nextcloud 28"
@echo " tests27 run nc_py_api tests for Nextcloud 27"
@echo " tests26 run nc_py_api tests for Nextcloud 26"

.PHONY: register28
register28:
/bin/sh scripts/dev_register.sh master-nextcloud-1 nextcloud.local

.PHONY: register27
register27:
/bin/sh scripts/dev_register.sh master-stable27-1 stable27.local

.PHONY: register26
register26:
/bin/sh scripts/dev_register.sh master-stable26-1 stable26.local

.PHONY: tests28
tests28:
NEXTCLOUD_URL=http://nextcloud.local python3 -m pytest

.PHONY: tests27
tests27:
NEXTCLOUD_URL=http://stable27.local python3 -m pytest

.PHONY: tests26
tests26:
NEXTCLOUD_URL=http://stable26.local python3 -m pytest
74 changes: 74 additions & 0 deletions benchmarks/ae_overhead_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import sys

import matplotlib.pyplot as plt
import numpy as np
from conf import NC_CFGS, init_nc, init_nc_app, init_nc_by_app_pass

NC_VERSIONS = []


def measure_overhead(measure, title: str):
penguin_means = {
"Password": [],
"AppPassword": [],
"AppEcosystem": [],
}

for k, v in NC_CFGS.items():
NC_VERSIONS.append(init_nc_app(k, v).srv_version["string"])

for k, v in NC_CFGS.items():
nc = init_nc(k, v)
if nc:
result_nc, time_nc = measure(nc)
penguin_means["Password"].append(time_nc)
else:
penguin_means["Password"].append(0)

nc_ap = init_nc_by_app_pass(k, v)
if nc_ap:
result_nc_ap, time_nc_ap = measure(nc_ap)
penguin_means["AppPassword"].append(time_nc_ap)
else:
penguin_means["AppPassword"].append(0)

nc_ae = init_nc_app(k, v)
result_nc_ae, time_nc_ae = measure(nc_ae)
penguin_means["AppEcosystem"].append(time_nc_ae)

# Uncomment only for functions that return predictable values.
# if result_nc is not None:
# assert result_nc == result_nc_ae
# if result_nc_ap is not None:
# assert result_nc_ap == result_nc_ae

penguin_means = {k: v for k, v in penguin_means.items() if v}

x = np.arange(len(NC_VERSIONS)) # the label locations
width = 0.25 # the width of the bars
multiplier = 0

fig, ax = plt.subplots(layout="constrained")

for attribute, measurement in penguin_means.items():
offset = width * multiplier
rects = ax.bar(x + offset, measurement, width, label=attribute)
ax.bar_label(rects, padding=3)
multiplier += 1

ax.set_ylabel("Time to execute")
ax.set_title(title)
ax.set_xticks(x + width, NC_VERSIONS)
ax.legend(loc="upper left", ncols=3)
values = []
for v in penguin_means.values():
values.append(max(v))
ax.set_ylim(0, max(values) + 0.18 * max(values))


def os_id():
if sys.platform.lower() == "darwin":
return "macOS"
elif sys.platform.lower() == "win32":
return "Windows"
return "Linux"
33 changes: 33 additions & 0 deletions benchmarks/ae_overhead_dav_download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from getpass import getuser
from random import randbytes
from time import perf_counter
from typing import Any, Union

import matplotlib.pyplot as plt
from ae_overhead_common import measure_overhead, os_id
from cpuinfo import get_cpu_info

from nc_py_api import Nextcloud, NextcloudApp

ITERS = 30
CACHE_SESS = False


def measure_download_1mb(nc_obj: Union[Nextcloud, NextcloudApp]) -> [Any, float]:
__result = None
small_file_name = "1Mb.bin"
small_file = randbytes(1024 * 1024)
nc_obj.files.upload(small_file_name, small_file)
start_time = perf_counter()
for _ in range(ITERS):
nc_obj.files.download(small_file_name)
nc_obj._session.init_adapter(restart=not CACHE_SESS) # noqa
end_time = perf_counter()
nc_obj.files.delete(small_file_name, not_fail=True)
return __result, round((end_time - start_time) / ITERS, 3)


if __name__ == "__main__":
title = f"download 1mb({ITERS} iters, CACHE={CACHE_SESS}) - {os_id()}, {get_cpu_info()['brand_raw']}"
measure_overhead(measure_download_1mb, title)
plt.savefig(f"results/dav_download_1mb__cache{int(CACHE_SESS)}_iters{ITERS}__{getuser()}.png", dpi=200)
37 changes: 37 additions & 0 deletions benchmarks/ae_overhead_dav_download_stream.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from getpass import getuser
from io import BytesIO
from random import randbytes
from time import perf_counter
from typing import Any, Union

import matplotlib.pyplot as plt
from ae_overhead_common import measure_overhead, os_id
from cpuinfo import get_cpu_info

from nc_py_api import Nextcloud, NextcloudApp

ITERS = 10
CACHE_SESS = False


def measure_download_100mb(nc_obj: Union[Nextcloud, NextcloudApp]) -> [Any, float]:
__result = None
medium_file_name = "100Mb.bin"
medium_file = BytesIO()
medium_file.write(randbytes(100 * 1024 * 1024))
medium_file.seek(0)
nc_obj.files.upload_stream(medium_file_name, medium_file)
start_time = perf_counter()
for _ in range(ITERS):
medium_file.seek(0)
nc_obj.files.download2stream(medium_file_name, medium_file)
nc_obj._session.init_adapter(restart=not CACHE_SESS) # noqa
end_time = perf_counter()
nc_obj.files.delete(medium_file_name, not_fail=True)
return __result, round((end_time - start_time) / ITERS, 3)


if __name__ == "__main__":
title = f"download stream 100mb({ITERS} iters, CACHE={CACHE_SESS}) - {os_id()}, {get_cpu_info()['brand_raw']}"
measure_overhead(measure_download_100mb, title)
plt.savefig(f"results/dav_download_stream_100mb__cache{int(CACHE_SESS)}_iters{ITERS}__{getuser()}.png", dpi=200)
32 changes: 32 additions & 0 deletions benchmarks/ae_overhead_dav_upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from getpass import getuser
from random import randbytes
from time import perf_counter
from typing import Any, Union

import matplotlib.pyplot as plt
from ae_overhead_common import measure_overhead, os_id
from cpuinfo import get_cpu_info

from nc_py_api import Nextcloud, NextcloudApp

ITERS = 30
CACHE_SESS = False


def measure_upload_1mb(nc_obj: Union[Nextcloud, NextcloudApp]) -> [Any, float]:
__result = None
small_file_name = "1Mb.bin"
small_file = randbytes(1024 * 1024)
start_time = perf_counter()
for _ in range(ITERS):
nc_obj.files.upload(small_file_name, small_file)
nc_obj._session.init_adapter(restart=not CACHE_SESS) # noqa
end_time = perf_counter()
nc_obj.files.delete(small_file_name, not_fail=True)
return __result, round((end_time - start_time) / ITERS, 3)


if __name__ == "__main__":
title = f"upload 1mb({ITERS} iters, CACHE={CACHE_SESS}) - {os_id()}, {get_cpu_info()['brand_raw']}"
measure_overhead(measure_upload_1mb, title)
plt.savefig(f"results/dav_upload_1mb__cache{int(CACHE_SESS)}_iters{ITERS}__{getuser()}.png", dpi=200)
35 changes: 35 additions & 0 deletions benchmarks/ae_overhead_dav_upload_stream.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from getpass import getuser
from io import BytesIO
from random import randbytes
from time import perf_counter
from typing import Any, Union

import matplotlib.pyplot as plt
from ae_overhead_common import measure_overhead, os_id
from cpuinfo import get_cpu_info

from nc_py_api import Nextcloud, NextcloudApp

ITERS = 10
CACHE_SESS = False


def measure_upload_100mb(nc_obj: Union[Nextcloud, NextcloudApp]) -> [Any, float]:
__result = None
medium_file_name = "100Mb.bin"
medium_file = BytesIO()
medium_file.write(randbytes(100 * 1024 * 1024))
start_time = perf_counter()
for _ in range(ITERS):
medium_file.seek(0)
nc_obj.files.upload_stream(medium_file_name, medium_file)
nc_obj._session.init_adapter(restart=not CACHE_SESS) # noqa
end_time = perf_counter()
nc_obj.files.delete(medium_file_name, not_fail=True)
return __result, round((end_time - start_time) / ITERS, 3)


if __name__ == "__main__":
title = f"upload stream 100mb({ITERS} iters, CACHE={CACHE_SESS}) - {os_id()}, {get_cpu_info()['brand_raw']}"
measure_overhead(measure_upload_100mb, title)
plt.savefig(f"results/dav_upload_stream_100mb__cache{int(CACHE_SESS)}_iters{ITERS}__{getuser()}.png", dpi=200)
77 changes: 0 additions & 77 deletions benchmarks/ae_overhead_heavy_op.py

This file was deleted.

Loading

0 comments on commit 65fc062

Please sign in to comment.