From 0313261e16c30205aac76d9aced01e0e485e022f Mon Sep 17 00:00:00 2001 From: Peter Kraft Date: Sun, 10 Nov 2024 21:07:24 -0800 Subject: [PATCH] Remove Unnecessary psutil Dependency (#151) --- dbos/_admin_sever.py | 14 -------------- pdm.lock | 30 +----------------------------- pyproject.toml | 2 -- tests/test_admin_server.py | 18 ------------------ 4 files changed, 1 insertion(+), 63 deletions(-) diff --git a/dbos/_admin_sever.py b/dbos/_admin_sever.py index 03725beb..81a2bd2e 100644 --- a/dbos/_admin_sever.py +++ b/dbos/_admin_sever.py @@ -6,8 +6,6 @@ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer from typing import TYPE_CHECKING, Any, List, TypedDict -import psutil - from ._logger import dbos_logger from ._recovery import recover_pending_workflows @@ -16,7 +14,6 @@ _health_check_path = "/dbos-healthz" _workflow_recovery_path = "/dbos-workflow-recovery" -_perf_path = "/dbos-perf" _deactivate_path = "/deactivate" @@ -55,17 +52,6 @@ def do_GET(self) -> None: self.send_response(200) self._end_headers() self.wfile.write("healthy".encode("utf-8")) - elif self.path == _perf_path: - # Compares system CPU times elapsed since last call or module import, returning immediately (non blocking). - cpu_percent = psutil.cpu_percent(interval=None) / 100.0 - perf_util: PerfUtilization = { - "idle": 1.0 - cpu_percent, - "active": cpu_percent, - "utilization": cpu_percent, - } - self.send_response(200) - self._end_headers() - self.wfile.write(json.dumps(perf_util).encode("utf-8")) elif self.path == _deactivate_path: dbos_logger.info("Deactivating DBOS") # Stop all scheduled workflows, queues, and kafka loops diff --git a/pdm.lock b/pdm.lock index 69c3bfa8..61378d71 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "dev"] strategy = ["inherit_metadata"] lock_version = "4.5.0" -content_hash = "sha256:c395bcec0ded7af2c12f347ebc9be700f4aa5be4fbbc2f387519f048a429f73d" +content_hash = "sha256:4f348668cbe0c5cfa26ec16291ef3b07f8560e6eddd730d83ee836241e6ef712" [[metadata.targets]] requires_python = ">=3.9" @@ -1147,23 +1147,6 @@ files = [ {file = "protobuf-4.25.5.tar.gz", hash = "sha256:7f8249476b4a9473645db7f8ab42b02fe1488cbe5fb72fddd445e0665afd8584"}, ] -[[package]] -name = "psutil" -version = "6.0.0" -requires_python = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,>=2.7" -summary = "Cross-platform lib for process and system monitoring in Python." -groups = ["default"] -files = [ - {file = "psutil-6.0.0-cp36-abi3-macosx_10_9_x86_64.whl", hash = "sha256:c588a7e9b1173b6e866756dde596fd4cad94f9399daf99ad8c3258b3cb2b47a0"}, - {file = "psutil-6.0.0-cp36-abi3-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6ed2440ada7ef7d0d608f20ad89a04ec47d2d3ab7190896cd62ca5fc4fe08bf0"}, - {file = "psutil-6.0.0-cp36-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5fd9a97c8e94059b0ef54a7d4baf13b405011176c3b6ff257c247cae0d560ecd"}, - {file = "psutil-6.0.0-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e2e8d0054fc88153ca0544f5c4d554d42e33df2e009c4ff42284ac9ebdef4132"}, - {file = "psutil-6.0.0-cp37-abi3-win32.whl", hash = "sha256:a495580d6bae27291324fe60cea0b5a7c23fa36a7cd35035a16d93bdcf076b9d"}, - {file = "psutil-6.0.0-cp37-abi3-win_amd64.whl", hash = "sha256:33ea5e1c975250a720b3a6609c490db40dae5d83a4eb315170c4fe0d8b1f34b3"}, - {file = "psutil-6.0.0-cp38-abi3-macosx_11_0_arm64.whl", hash = "sha256:ffe7fc9b6b36beadc8c322f84e1caff51e8703b88eee1da46d1e3a6ae11b4fd0"}, - {file = "psutil-6.0.0.tar.gz", hash = "sha256:8faae4f310b6d969fa26ca0545338b21f73c6b15db7c4a8d934a5482faa818f2"}, -] - [[package]] name = "psycopg" version = "3.2.3" @@ -1856,17 +1839,6 @@ files = [ {file = "types_jsonschema-4.23.0.20240813-py3-none-any.whl", hash = "sha256:be283e23f0b87547316c2ee6b0fd36d95ea30e921db06478029e10b5b6aa6ac3"}, ] -[[package]] -name = "types-psutil" -version = "6.0.0.20241011" -requires_python = ">=3.8" -summary = "Typing stubs for psutil" -groups = ["dev"] -files = [ - {file = "types-psutil-6.0.0.20241011.tar.gz", hash = "sha256:5f5c71d02f7a018249d457e080f85966a31a8200644c5459f63cf02be1d85c04"}, - {file = "types_psutil-6.0.0.20241011-py3-none-any.whl", hash = "sha256:7ae5b398d6c0ae895ca3ca8a6a123ca05bb3b3d7297ff54981447300375a9c4e"}, -] - [[package]] name = "types-pyyaml" version = "6.0.12.20240917" diff --git a/pyproject.toml b/pyproject.toml index 518808e3..b323c1c1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,6 @@ dependencies = [ "opentelemetry-exporter-otlp-proto-http>=1.27.0", "python-dateutil>=2.9.0.post0", "fastapi[standard]>=0.115.2", - "psutil>=6.0.0", "tomlkit>=0.13.2", "psycopg[binary]>=3.1", # Keep compatibility with 3.1--older Python installations/machines can't always install 3.2 ] @@ -49,7 +48,6 @@ dev = [ "black>=24.10.0", "pre-commit>=4.0.1", "isort>=5.13.2", - "types-psutil>=6.0.0.20240621", "requests>=2.32.3", "types-requests>=2.32.0.20240914", "httpx>=0.27.2", diff --git a/tests/test_admin_server.py b/tests/test_admin_server.py index 88fbe2b0..32a19bb6 100644 --- a/tests/test_admin_server.py +++ b/tests/test_admin_server.py @@ -23,23 +23,6 @@ def test_admin_endpoints(dbos: DBOS) -> None: assert response.status_code == 200 assert response.json() == [] - # Test GET /dbos-perf - response = requests.get("http://localhost:3001/dbos-perf", timeout=5) - assert response.status_code == 200 - perf_util = response.json() - assert perf_util is not None - assert "idle" in perf_util - assert "active" in perf_util - assert "utilization" in perf_util - - # Test GET /dbos-perf again, should be a valid utilization between 0~1 - time.sleep(0.2) - response = requests.get("http://localhost:3001/dbos-perf", timeout=5) - assert response.status_code == 200 - perf_util = response.json() - assert perf_util["utilization"] >= 0.0 - assert perf_util["utilization"] <= 1.0 - # Test GET not found response = requests.get("http://localhost:3001/stuff", timeout=5) assert response.status_code == 404 @@ -55,7 +38,6 @@ def test_admin_endpoints(dbos: DBOS) -> None: assert event.is_set(), "Event is not set!" - def test_admin_recovery(dbos: DBOS) -> None: os.environ["DBOS__VMID"] = "testexecutor" os.environ["DBOS__APPVERSION"] = "testversion"