Skip to content

Commit a950f84

Browse files
increase timeout. use threading
1 parent cd1805e commit a950f84

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

backend.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ RUN pip install poetry \
2323
&& pip install -r requirements.txt
2424

2525

26-
CMD exec uvicorn --proxy-headers --host=0.0.0.0 $UVICORN_ENTRYPOINT
26+
CMD exec uvicorn --proxy-headers --timeout-keep-alive 300 --host=0.0.0.0 $UVICORN_ENTRYPOINT

backend/src/backend/user_session/routers/surface/router.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
from typing import List, Tuple
55
import logging
6+
from concurrent.futures import ThreadPoolExecutor
67
from aiocache import Cache
8+
79
import numpy as np
810
from fastapi.responses import ORJSONResponse
911

@@ -14,7 +16,7 @@
1416
from src.backend.auth.auth_helper import AuthenticatedUser, AuthHelper
1517

1618
from src.services.sumo_access.surface_access import SurfaceAccess
17-
19+
import asyncio
1820
from src.backend.primary.routers.surface import schemas
1921
from .test_async import async_get_cached_surf
2022
from .test_go import go_get_surface_blobs
@@ -97,11 +99,6 @@ async def well_intersection_reals_from_user_session(
9799
# await cache.set(f"{authenticated_user._user_id}-{uuid}", surface)
98100
surfaces.append(surface)
99101

100-
# print(surfaces)
101-
# return []
102-
103-
intersections = []
104-
105102
fence_arr = np.array(
106103
[
107104
polyline.x_points,
@@ -110,13 +107,21 @@ async def well_intersection_reals_from_user_session(
110107
polyline.cum_length,
111108
]
112109
).T
113-
for surf in surfaces:
110+
111+
def worker(surf):
114112
line = surf.get_randomline(fence_arr)
115113
intersection = schemas.SurfaceIntersectionPoints(
116114
name=f"{surf.name}",
117115
cum_length=line[:, 0].tolist(),
118116
z_array=line[:, 1].tolist(),
119117
)
120-
intersections.append(intersection)
118+
return intersection
119+
120+
loop = asyncio.get_running_loop()
121+
122+
with ThreadPoolExecutor() as executor:
123+
tasks = [loop.run_in_executor(executor, worker, surf) for surf in surfaces]
124+
intersections = await asyncio.gather(*tasks)
121125

122-
return ORJSONResponse([section.dict() for section in intersections])
126+
result = [intersection.dict() for intersection in intersections]
127+
return ORJSONResponse(result)

backend/src/backend/user_session/routers/surface/test_go.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ def go_get_surface_blobs(sumo_token: str, case_uuid: str, object_ids: list[str])
3030
res = GetZippedBlobs(json.dumps(new_request).encode("utf-8"))
3131
res_string = ctypes.string_at(res).decode("ascii")
3232
data_map_b64 = json.loads(res_string)
33-
33+
print("Done downloading surfaces", flush=True)
3434
surfaces = {}
3535
for object_id, b64_blob in data_map_b64.items():
3636
bytestr = base64.b64decode(b64_blob)
3737
xtgeo_surface = xtgeo.surface_from_file(BytesIO(bytestr), fformat="irap_binary")
3838
surfaces[object_id] = xtgeo_surface
39-
39+
print("Done decoding surfaces", flush=True)
4040
return surfaces

0 commit comments

Comments
 (0)