Skip to content

Commit 33cd4b4

Browse files
fix cpu<1 cases
1 parent 823ffbc commit 33cd4b4

File tree

5 files changed

+46
-17
lines changed

5 files changed

+46
-17
lines changed

bigframes/functions/_function_client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,10 @@ def provision_bq_remote_function(
645645
# assumption is most bigframes functions are cpu bound, single-threaded and many won't release GIL
646646
# therefore, want to allocate a worker for each cpu, and allow a concurrent request per worker
647647
expected_milli_cpus = (
648-
cloud_function_cpus * 1000
649-
) or _infer_milli_cpus_from_memory(cloud_function_memory_mib)
648+
int(cloud_function_cpus * 1000)
649+
if (cloud_function_cpus is not None)
650+
else _infer_milli_cpus_from_memory(cloud_function_memory_mib)
651+
)
650652
workers = -(expected_milli_cpus // -1000) # ceil(cpus) without invoking floats
651653
threads = 4 # (per worker)
652654
# max concurrency==1 for vcpus < 1 hard limit from cloud run

bigframes/functions/_function_session.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def remote_function(
249249
Literal["all", "private-ranges-only", "unspecified"]
250250
] = None,
251251
cloud_function_memory_mib: Optional[int] = None,
252-
cloud_function_cpus: Optional[int] = None,
252+
cloud_function_cpus: Optional[float] = None,
253253
cloud_function_ingress_settings: Literal[
254254
"all", "internal-only", "internal-and-gclb"
255255
] = "internal-only",
@@ -445,8 +445,8 @@ def remote_function(
445445
default memory of cloud functions be allocated, pass `None`. See
446446
for more details
447447
https://cloud.google.com/functions/docs/configuring/memory.
448-
cloud_function_cpus (int, Optional):
449-
The amounts of memory (in mebibytes) to allocate for the cloud
448+
cloud_function_cpus (float, Optional):
449+
The number of cpus to allocate for the cloud
450450
function (2nd gen) created.
451451
https://docs.cloud.google.com/run/docs/configuring/services/cpu.
452452
cloud_function_ingress_settings (str, Optional):

bigframes/pandas/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def remote_function(
8989
Literal["all", "private-ranges-only", "unspecified"]
9090
] = None,
9191
cloud_function_memory_mib: Optional[int] = None,
92-
cloud_function_cpus: Optional[int] = None,
92+
cloud_function_cpus: Optional[float] = None,
9393
cloud_function_ingress_settings: Literal[
9494
"all", "internal-only", "internal-and-gclb"
9595
] = "internal-only",

bigframes/session/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,7 +1538,7 @@ def remote_function(
15381538
Literal["all", "private-ranges-only", "unspecified"]
15391539
] = None,
15401540
cloud_function_memory_mib: Optional[int] = None,
1541-
cloud_function_cpus: Optional[int] = None,
1541+
cloud_function_cpus: Optional[float] = None,
15421542
cloud_function_ingress_settings: Literal[
15431543
"all", "internal-only", "internal-and-gclb"
15441544
] = "internal-only",
@@ -1719,8 +1719,8 @@ def remote_function(
17191719
default memory of cloud functions be allocated, pass `None`. See
17201720
for more details
17211721
https://cloud.google.com/functions/docs/configuring/memory.
1722-
cloud_function_cpus (int, Optional):
1723-
The amounts of memory (in mebibytes) to allocate for the cloud
1722+
cloud_function_cpus (float, Optional):
1723+
The number of cpus to allocate for the cloud
17241724
function (2nd gen) created.
17251725
https://docs.cloud.google.com/run/docs/configuring/services/cpu.
17261726
cloud_function_ingress_settings (str, Optional):

tests/system/large/functions/test_remote_function.py

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,19 +2093,40 @@ def foo_list(x: pandas.Series, y0: float, y1, y2) -> list[str]:
20932093

20942094

20952095
@pytest.mark.parametrize(
2096-
("memory_mib_args", "expected_memory"),
2096+
(
2097+
"memory_mib_args",
2098+
"expected_memory",
2099+
"expected_cpus",
2100+
),
20972101
[
2098-
pytest.param({}, "1024Mi", id="no-set"),
2099-
pytest.param({"cloud_function_memory_mib": None}, "256M", id="set-None"),
2100-
pytest.param({"cloud_function_memory_mib": 128}, "128Mi", id="set-128"),
2101-
pytest.param({"cloud_function_memory_mib": 1024}, "1024Mi", id="set-1024"),
2102-
pytest.param({"cloud_function_memory_mib": 4096}, "4096Mi", id="set-4096"),
2103-
pytest.param({"cloud_function_memory_mib": 32768}, "32768Mi", id="set-32768"),
2102+
pytest.param({}, "1024Mi", None, id="no-set"),
2103+
pytest.param(
2104+
{"cloud_function_memory_mib": None}, "1024Mi", None, id="set-None"
2105+
),
2106+
pytest.param({"cloud_function_memory_mib": 128}, "128Mi", None, id="set-128"),
2107+
pytest.param(
2108+
{"cloud_function_memory_mib": 512, "cloud_function_cpus": 0.6},
2109+
"512Mi",
2110+
"0.6",
2111+
id="set-512",
2112+
),
2113+
pytest.param(
2114+
{"cloud_function_memory_mib": 1024}, "1024Mi", None, id="set-1024"
2115+
),
2116+
pytest.param(
2117+
{"cloud_function_memory_mib": 4096, "cloud_function_cpus": 4},
2118+
"4096Mi",
2119+
"4",
2120+
id="set-4096",
2121+
),
2122+
pytest.param(
2123+
{"cloud_function_memory_mib": 32768}, "32768Mi", None, id="set-32768"
2124+
),
21042125
],
21052126
)
21062127
@pytest.mark.flaky(retries=2, delay=120)
21072128
def test_remote_function_gcf_memory(
2108-
session, scalars_dfs, memory_mib_args, expected_memory
2129+
session, scalars_dfs, memory_mib_args, expected_memory, expected_cpus
21092130
):
21102131
try:
21112132

@@ -2121,6 +2142,12 @@ def square(x: int) -> int:
21212142
name=square_remote.bigframes_cloud_function
21222143
)
21232144
assert gcf.service_config.available_memory == expected_memory
2145+
if expected_cpus is not None:
2146+
assert gcf.service_config.available_cpu == expected_cpus
2147+
if float(gcf.service_config.available_cpu) >= 1.0:
2148+
assert gcf.service_config.max_instance_request_concurrency >= float(
2149+
gcf.service_config.available_cpu
2150+
)
21242151

21252152
scalars_df, scalars_pandas_df = scalars_dfs
21262153

0 commit comments

Comments
 (0)