decentriq_util 0.1.0.dev8__tar.gz → 0.1.0.dev10__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.dev10
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()
@@ -145,7 +148,6 @@ def _determine_optimal_spark_settings(
145
148
  ("spark.driver.cores", str(cpu_count)),
146
149
  ("spark.driver.memory", str(spark_memory_4096)),
147
150
  ]
148
- print("Spark settings:\n" + f"\n".join([str(x) for x in settings]))
149
151
 
150
152
  return settings
151
153
 
@@ -154,7 +156,7 @@ def _create_spark_session(
154
156
  name: str = "local_spark_session",
155
157
  parallelism: int = 8,
156
158
  heap_size: Optional[int] = None,
157
- heap_size_extra_room: int = 512 * 1024 * 1024,
159
+ heap_size_extra_room: int = _DEFAULT_HEAP_SIZE_EXTRA_ROOM,
158
160
  config: list[Tuple[str, Any]] = [],
159
161
  java_tmp_dir = "/output",
160
162
  ) -> SparkSession:
@@ -189,6 +191,9 @@ def _create_spark_session(
189
191
  )
190
192
  for (key, value) in config:
191
193
  ss = ss.config(key, value)
194
+
195
+ print("Spark settings:\n" + f"\n".join([str(x) for x in config]))
196
+
192
197
  return ss.getOrCreate()
193
198
 
194
199
 
@@ -231,7 +236,10 @@ def spark_session(temp_dir: str = "/scratch", input_files: list[str] = None, **k
231
236
  config_dict = dict(config)
232
237
  if input_files is not None and input_files:
233
238
  optimal_settings = _determine_optimal_spark_settings(
234
- input_files, heap_size_extra_room=kwargs.get("heap_size_extra_room")
239
+ input_files,
240
+ heap_size_extra_room=kwargs.get(
241
+ "heap_size_extra_room", _DEFAULT_HEAP_SIZE_EXTRA_ROOM
242
+ )
235
243
  )
236
244
  for key, value in optimal_settings:
237
245
  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-dev10"
4
4
  description = "Utility functions for Python code run in Decentriq workers"
5
5
  authors = ["hafenr <robin.hafen@gmail.com>"]
6
6