Skip to content

Commit ef5f8c9

Browse files
MP
1 parent 2b542d9 commit ef5f8c9

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

backend/src/backend/primary/user_session_proxy.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ async def _create_new_job(self, user_id: str) -> None:
8888
# these could be dynamic based on e.g. the selected ensemble sizess by the user.
8989
json={
9090
"resources": {
91-
"limits": {"memory": "64GiB", "cpu": "2"},
92-
"requests": {"memory": "32GiB", "cpu": "1"},
91+
"limits": {"memory": "64GiB", "cpu": "4"},
92+
"requests": {"memory": "32GiB", "cpu": "2"},
9393
}
9494
},
9595
)

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

+30-22
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from typing import List, Tuple
55
import logging
6-
from concurrent.futures import ThreadPoolExecutor
6+
from concurrent.futures import ProcessPoolExecutor
77
from aiocache import Cache
88

99
import numpy as np
@@ -80,7 +80,9 @@ async def well_intersection_reals_from_user_session(
8080
extra={"total_mb": tot_mb, "mb_per_s": tot_mb / dl_time_s},
8181
)
8282

83-
surfs = [xtgeo.surface_from_file(BytesIO(bytestr), fformat="irap_binary") for bytestr in res_array]
83+
# surfs = [xtgeo.surface_from_file(BytesIO(bytestr), fformat="irap_binary") for bytestr in res_array]
84+
surfaces = await load_xtgeo(res_array)
85+
print(f"convert surfs: {timer.lap_s():.2f}s", flush=True)
8486
fence_arr = np.array(
8587
[
8688
surface_fence_spec.x_points,
@@ -89,16 +91,9 @@ async def well_intersection_reals_from_user_session(
8991
surface_fence_spec.cum_length,
9092
]
9193
).T
94+
intersections = await make_intersections(surfaces, fence_arr)
9295

93-
for surf in surfs:
94-
line = surf.get_randomline(fence_arr)
95-
intersection = schemas.SurfaceIntersectionPoints(
96-
name=f"{surf.name}",
97-
cum_length=line[:, 0].tolist(),
98-
z_array=line[:, 1].tolist(),
99-
)
100-
intersections.append(intersection)
101-
96+
print(f"intersect surfs: {timer.lap_s():.2f}s", flush=True)
10297
return ORJSONResponse([section.dict() for section in intersections])
10398

10499

@@ -212,24 +207,37 @@ def to_xtgeo(object_id, b64_blob):
212207
return downloaded_surface_dict
213208

214209

215-
async def make_intersections(surfaces, fence_arr):
216-
def make_intersection(surf):
217-
line = surf.get_randomline(fence_arr)
218-
intersection = schemas.SurfaceIntersectionPoints(
219-
name=f"{surf.name}",
220-
cum_length=line[:, 0].tolist(),
221-
z_array=line[:, 1].tolist(),
222-
)
223-
return intersection
210+
def make_intersection(surf, fence_arr):
211+
line = surf.get_randomline(fence_arr)
212+
intersection = schemas.SurfaceIntersectionPoints(
213+
name=f"{surf.name}",
214+
cum_length=line[:, 0].tolist(),
215+
z_array=line[:, 1].tolist(),
216+
)
217+
return intersection
218+
224219

220+
async def make_intersections(surfaces, fence_arr):
225221
loop = asyncio.get_running_loop()
226222

227-
with ThreadPoolExecutor() as executor:
228-
tasks = [loop.run_in_executor(executor, make_intersection, surf) for surf in surfaces]
223+
with ProcessPoolExecutor() as executor:
224+
tasks = [loop.run_in_executor(executor, make_intersection, surf, fence_arr) for surf in surfaces]
229225
intersections = await asyncio.gather(*tasks)
230226
return intersections
231227

232228

229+
def load_surf(bytestr) -> xtgeo.RegularSurface:
230+
return xtgeo.surface_from_file(BytesIO(bytestr), fformat="irap_binary")
231+
232+
233+
async def load_xtgeo(res_array):
234+
loop = asyncio.get_running_loop()
235+
with ProcessPoolExecutor() as executor:
236+
tasks = [loop.run_in_executor(executor, load_surf, bytestr) for bytestr in res_array]
237+
surfaces = await asyncio.gather(*tasks)
238+
return surfaces
239+
240+
233241
def get_uuids(case_uuid, ensemble_name, realization_nums, snames, sattr, bearer_token):
234242
sumo_client = SumoClient(env="prod", token=bearer_token, interactive=False)
235243
case_collection = CaseCollection(sumo_client).filter(uuid=case_uuid)

0 commit comments

Comments
 (0)