with ExitStack() as stack: if "--worker" not in sys.argv: cmd = [PYTHON, SETUP_PY, "develop"] proc = subprocess.run( cmd, cwd=DATADIR, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT, ) if proc.returncode != 0: print(f'# running: {" ".join(cmd)} (in {DATADIR})') subprocess.run(cmd, cwd=DATADIR, check=True) cmd_app = [UWSGI, PRODUCTION_INI] stack.enter_context( netutils.serving(cmd_app, DATADIR, SOCK, kill=True)) cmd_web = [NGINX, "-c", NGINX_CONF, "-p", DATADIR] stack.enter_context( netutils.serving(cmd_web, DATADIR, ADDR, pause=0.010, quiet=False)) runner = pyperf.Runner() runner.metadata['description'] = "Test the performance of kinto" runner.bench_time_func("kinto", bench_kinto)
elapsed += t1 - t0 times.append(t0) if legacy and (i % 100 == 0): print(i, t0 - start) times.append(pyperf.perf_counter()) if legacy: total = times[-1] - start print("%.2fs (%.2f ms / %.3freq/s)" % (total, total / loops * 1e3, loops / total)) return elapsed, times ############################# # the script if __name__ == "__main__": from legacyutils import maybe_handle_legacy if "--legacy" in sys.argv: with netutils.serving(ARGV, DATADIR, "127.0.0.1:8000"): maybe_handle_legacy(_bench_flask_requests, legacyarg='legacy') if "--worker" not in sys.argv: context = netutils.serving(ARGV, DATADIR, "127.0.0.1:8000") else: context = nullcontext() with context: runner = pyperf.Runner() runner.metadata['description'] = "Test the performance of flask" runner.bench_time_func("flaskblogging", bench_flask_requests)
t1 = pyperf.perf_counter() elapsed += t1 - t0 times.append(t0) if legacy and (i % 100 == 0): print(i, t0 - start) times.append(pyperf.perf_counter()) if legacy: total = times[-1] - start print("%.2fs (%.3freq/s)" % (total, loops / total)) print(loops, elapsed / loops) return elapsed, times ############################# # the script if __name__ == "__main__": from legacyutils import maybe_handle_legacy maybe_handle_legacy(_bench_aiohttp_requests, legacyarg='legacy') if "--worker" not in sys.argv: context = netutils.serving(ARGV, DATADIR, "127.0.0.1:8080") else: context = nullcontext() with context: runner = pyperf.Runner() runner.metadata['description'] = "Test the performance of aiohttp" runner.bench_time_func("aiohttp", bench_aiohttp_requests)
# First, set up the site. if args.setup: sitedir, elapsed = setup(datadir) if args.legacy: print("%.2fs to initialize db" % (elapsed,)) print(f"site created in {sitedir}") if not args.serve: print(f"now run {sys.executable} {sys.argv[0]} --serve {datadir}") else: # This is what a previous call to setup() would have returned. sitedir = os.path.join(datadir, SITE_NAME) # Then run the benchmark. if args.serve: if "--worker" not in sys.argv: context = netutils.serving(ARGV_SERVE, sitedir, "127.0.0.1:8000") else: context = nullcontext() with context: if args.legacy: from legacyutils import maybe_handle_legacy sys.argv[1:] = ["--legacy"] + legacy_args maybe_handle_legacy(_bench_djangocms_requests, sitedir, legacyarg='legacy') sys.exit(0) runner.datadir = datadir def time_func(loops, *args): return bench_djangocms_requests(*args, loops=loops) runner.bench_time_func("djangocms", time_func, sitedir,
requests_get("http://localhost:8000/blog/").text t1 = pyperf.perf_counter() elapsed += t1 - t0 times.append(t0) if legacy and (i % 100 == 0): print(i, t0 - start) times.append(pyperf.perf_counter()) if legacy: total = times[-1] - start print("%.2fs (%.3freq/s)" % (total, loops / total)) return elapsed, times ############################# # the script if __name__ == "__main__": from legacyutils import maybe_handle_legacy maybe_handle_legacy(_bench_gunicorn, legacyarg='legacy') if "--worker" not in sys.argv: context = netutils.serving(ARGV, DATADIR, ADDR) else: context = nullcontext() with context: runner = pyperf.Runner() runner.metadata['description'] = "Test the performance of gunicorn" runner.bench_time_func("gunicorn", bench_gunicorn)