Skip to content

reuse async http client in cluster servlet #1547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions runhouse/servers/cluster_servlet.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import asyncio
import copy
import datetime
import json
import os
import threading
from typing import Any, Dict, List, Optional, Set, Tuple, Union
Expand Down Expand Up @@ -84,6 +83,7 @@ async def __init__(
self._api_server_url = self.cluster_config.get(
"api_server_url", rns_client.api_server_url
)
self.client = httpx.AsyncClient()
self.pid = get_pid()
self.process = psutil.Process(pid=self.pid)
self.gpu_metrics = None # will be updated only if this is a gpu cluster.
Expand Down Expand Up @@ -303,11 +303,9 @@ async def asave_status_metrics_to_den(self, status: dict):
"env_servlet_processes": servlet_processes,
}

client = httpx.AsyncClient()

return await client.post(
return await self.client.post(
f"{self._api_server_url}/resource/{self._cluster_uri}/cluster/status",
data=json.dumps(status_data),
json=status_data,
headers=rns_client.request_headers(),
)

Expand Down Expand Up @@ -731,9 +729,9 @@ async def send_cluster_logs_to_den(
"end_line": new_end_log_line,
}

post_logs_resp = requests.post(
post_logs_resp = await self.client.post(
f"{self._api_server_url}/resource/{self._cluster_uri}/logs",
data=json.dumps(logs_data),
json=logs_data,
headers=rns_client.request_headers(),
)

Expand Down
Loading