decentriq_util 0.1.0.dev8__tar.gz → 0.1.0.dev9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: decentriq_util
3
- Version: 0.1.0.dev8
3
+ Version: 0.1.0.dev9
4
4
  Summary: Utility functions for Python code run in Decentriq workers
5
5
  Author: hafenr
6
6
  Author-email: robin.hafen@gmail.com
@@ -11,6 +11,9 @@ import pyarrow.parquet as pq
11
11
  from pyspark.sql import SparkSession
12
12
 
13
13
 
14
+ _DEFAULT_HEAP_SIZE_EXTRA_ROOM = 2 * 512 * 1024 * 1024
15
+
16
+
14
17
  def _get_cgroup_memory() -> int:
15
18
  max_memory_str = None
16
19
  if os.path.isfile("/sys/fs/cgroup/memory.max"):
@@ -126,12 +129,12 @@ def _get_num_partitions(
126
129
 
127
130
  def _determine_optimal_spark_settings(
128
131
  files: list[str],
129
- heap_size_extra_room: Optional[int] = 2 * 512 * 1024 * 1024
132
+ heap_size_extra_room = _DEFAULT_HEAP_SIZE_EXTRA_ROOM
130
133
  ) -> list[Tuple[str, str]]:
131
134
  def get_spark_memory() -> int:
132
135
  """Determine the amount of memory available to spark"""
133
136
  cgroup_memory = _get_cgroup_memory()
134
- spark_memory = cgroup_memory - (heap_size_extra_room or 512 * 1024 * 1024)
137
+ spark_memory = cgroup_memory - heap_size_extra_room
135
138
  return spark_memory
136
139
 
137
140
  cpu_count = multiprocessing.cpu_count()
@@ -154,7 +157,7 @@ def _create_spark_session(
154
157
  name: str = "local_spark_session",
155
158
  parallelism: int = 8,
156
159
  heap_size: Optional[int] = None,
157
- heap_size_extra_room: int = 512 * 1024 * 1024,
160
+ heap_size_extra_room: int = _DEFAULT_HEAP_SIZE_EXTRA_ROOM,
158
161
  config: list[Tuple[str, Any]] = [],
159
162
  java_tmp_dir = "/output",
160
163
  ) -> SparkSession:
@@ -231,7 +234,10 @@ def spark_session(temp_dir: str = "/scratch", input_files: list[str] = None, **k
231
234
  config_dict = dict(config)
232
235
  if input_files is not None and input_files:
233
236
  optimal_settings = _determine_optimal_spark_settings(
234
- input_files, heap_size_extra_room=kwargs.get("heap_size_extra_room")
237
+ input_files,
238
+ heap_size_extra_room=kwargs.get(
239
+ "heap_size_extra_room", _DEFAULT_HEAP_SIZE_EXTRA_ROOM
240
+ )
235
241
  )
236
242
  for key, value in optimal_settings:
237
243
  if key not in config_dict:
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "decentriq_util"
3
- version = "0.1.0-dev8"
3
+ version = "0.1.0-dev9"
4
4
  description = "Utility functions for Python code run in Decentriq workers"
5
5
  authors = ["hafenr <robin.hafen@gmail.com>"]
6
6