Skip to content

Commit c95a5d8

Browse files
andytwiggcopybara-github
authored andcommitted
Increase JAX IFRT proxy client connection timeout to 10 minutes.
PiperOrigin-RevId: 946138871
1 parent de948da commit c95a5d8

2 files changed

Lines changed: 55 additions & 4 deletions

File tree

pathwaysutils/proxy_backend.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,27 @@
1313
# limitations under the License.
1414
"""Register the IFRT Proxy as a backend for JAX."""
1515

16+
import os
1617
import jax
1718
from jax.extend import backend
1819
from jax.extend.backend import ifrt_proxy
1920

2021

2122
def register_backend_factory() -> None:
23+
"""Registers the IFRT Proxy backend factory with JAX."""
24+
25+
def make_client():
26+
options = ifrt_proxy.ClientConnectionOptions()
27+
timeout_secs = os.environ.get("PATHWAYS_PROXY_CONNECTION_TIMEOUT_SECS")
28+
if timeout_secs:
29+
options.connection_timeout_in_seconds = int(timeout_secs)
30+
return ifrt_proxy.get_client(
31+
jax.config.read("jax_backend_target"),
32+
options,
33+
)
34+
2235
backend.register_backend_factory(
2336
"proxy",
24-
lambda: ifrt_proxy.get_client(
25-
jax.config.read("jax_backend_target"),
26-
ifrt_proxy.ClientConnectionOptions(),
27-
),
37+
make_client,
2838
priority=-1,
2939
)

pathwaysutils/test/proxy_backend_test.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
"""Tests for the proxy backend module."""
1515

16+
import os
1617
from unittest import mock
1718

1819
from absl.testing import absltest
@@ -54,6 +55,46 @@ def test_proxy_backend_registration(self):
5455
proxy_backend.register_backend_factory()
5556
self.assertIn("proxy", backend.backends())
5657

58+
def test_proxy_backend_registration_with_timeout(self):
59+
mock_get_client = self.enter_context(
60+
mock.patch.object(
61+
ifrt_proxy,
62+
"get_client",
63+
return_value=mock.MagicMock(),
64+
)
65+
)
66+
self.enter_context(
67+
mock.patch.dict(
68+
os.environ, {"PATHWAYS_PROXY_CONNECTION_TIMEOUT_SECS": "42"}
69+
)
70+
)
71+
proxy_backend.register_backend_factory()
72+
self.assertIn("proxy", backend.backends())
73+
mock_get_client.assert_called_once()
74+
args, _ = mock_get_client.call_args
75+
self.assertEqual(args[0], "grpc://localhost:12345")
76+
options = args[1]
77+
self.assertEqual(options.connection_timeout_in_seconds, 42)
78+
79+
def test_proxy_backend_registration_without_timeout(self):
80+
mock_get_client = self.enter_context(
81+
mock.patch.object(
82+
ifrt_proxy,
83+
"get_client",
84+
return_value=mock.MagicMock(),
85+
)
86+
)
87+
self.enter_context(mock.patch.dict(os.environ))
88+
os.environ.pop("PATHWAYS_PROXY_CONNECTION_TIMEOUT_SECS", None)
89+
90+
proxy_backend.register_backend_factory()
91+
self.assertIn("proxy", backend.backends())
92+
mock_get_client.assert_called_once()
93+
args, _ = mock_get_client.call_args
94+
self.assertEqual(args[0], "grpc://localhost:12345")
95+
options = args[1]
96+
self.assertNotEqual(options.connection_timeout_in_seconds, 42)
97+
5798

5899
if __name__ == "__main__":
59100
absltest.main()

0 commit comments

Comments
 (0)