decentriq_util 0.1.0.dev10__tar.gz → 0.1.0.dev12__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.dev10
3
+ Version: 0.1.0.dev12
4
4
  Summary: Utility functions for Python code run in Decentriq workers
5
5
  Author: hafenr
6
6
  Author-email: robin.hafen@gmail.com
@@ -0,0 +1,9 @@
1
+ import logging
2
+
3
+
4
+ logger = logging.getLogger("decentriq_util")
5
+ ch = logging.StreamHandler()
6
+ ch.setLevel(logging.INFO)
7
+ formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
8
+ ch.setFormatter(formatter)
9
+ logger.addHandler(ch)
@@ -4,8 +4,8 @@ from contextlib import contextmanager
4
4
  import multiprocessing
5
5
  import math
6
6
  import os
7
- import shutil
8
7
  import psutil
8
+ from ..logger import logger
9
9
 
10
10
  import pyarrow.parquet as pq
11
11
  from pyspark.sql import SparkSession
@@ -36,7 +36,7 @@ def _get_cgroup_memory() -> int:
36
36
  if max_memory is not None:
37
37
  return max_memory
38
38
  else:
39
- print("Unable to determine available memory from cgroup, assuming 4G")
39
+ logger.info("Unable to determine available memory from cgroup, assuming 4G")
40
40
  return 4 * 1024 * 1024 * 1024
41
41
 
42
42
 
@@ -101,7 +101,7 @@ def _get_num_partitions(
101
101
 
102
102
  # Try to make partitions as big as possible s.t. each CPU is saturated,
103
103
  # while accounting for 50% overhead in spark.
104
- task_per_cpu = 3 # try to get at least this many tasks/partitions per CPU
104
+ task_per_cpu = 2 # try to get at least this many tasks/partitions per CPU
105
105
  max_target_partition_size = max(
106
106
  int(0.5 * available_memory / (task_per_cpu * cpu_count)) // megabyte_in_bytes * megabyte_in_bytes,
107
107
  min_partition_size
@@ -118,9 +118,9 @@ def _get_num_partitions(
118
118
  break
119
119
  target_partition_size = target_partition_size / 2
120
120
 
121
- print(f"File size: {file_size}")
122
- print(f"Max target partition size: {max_target_partition_size}")
123
- print(f"Target partition size: {target_partition_size}")
121
+ logger.info(f"File size: {file_size}")
122
+ logger.info(f"Max target partition size: {max_target_partition_size}")
123
+ logger.info(f"Target partition size: {target_partition_size}")
124
124
 
125
125
  num_partitions = int(math.ceil(file_size / target_partition_size))
126
126
 
@@ -192,7 +192,7 @@ def _create_spark_session(
192
192
  for (key, value) in config:
193
193
  ss = ss.config(key, value)
194
194
 
195
- print("Spark settings:\n" + f"\n".join([str(x) for x in config]))
195
+ logger.info("Spark settings:\n" + f"\n".join([str(x) for x in config]))
196
196
 
197
197
  return ss.getOrCreate()
198
198
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "decentriq_util"
3
- version = "0.1.0-dev10"
3
+ version = "0.1.0-dev12"
4
4
  description = "Utility functions for Python code run in Decentriq workers"
5
5
  authors = ["hafenr <robin.hafen@gmail.com>"]
6
6