-
Notifications
You must be signed in to change notification settings - Fork 88
[MMM-20372] Make pool_maxsize configurable. #1642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
import os | ||
import sys | ||
import trafaret as t | ||
import requests.adapters | ||
|
||
from contextvars import ContextVar | ||
from urllib.parse import urlparse, urlunparse | ||
|
||
|
@@ -153,10 +155,10 @@ def filter(self, record: logging.LogRecord) -> bool: | |
return not record.name.startswith("opentelemetry") | ||
|
||
|
||
def _setup_otel_logging(resource, multiprocessing=False): | ||
def _setup_otel_logging(resource, multiprocessing=False, session=None): | ||
logger_provider = LoggerProvider(resource=resource) | ||
set_logger_provider(logger_provider) | ||
exporter = OTLPLogExporter() | ||
exporter = OTLPLogExporter(session=session) | ||
if multiprocessing: | ||
logger_provider.add_log_record_processor(SimpleLogRecordProcessor(exporter)) | ||
else: | ||
|
@@ -168,16 +170,16 @@ def _setup_otel_logging(resource, multiprocessing=False): | |
return logger_provider | ||
|
||
|
||
def _setup_otel_metrics(resource): | ||
metric_exporter = OTLPMetricExporter() | ||
def _setup_otel_metrics(resource, session=None): | ||
metric_exporter = OTLPMetricExporter(session=session) | ||
metric_reader = PeriodicExportingMetricReader(metric_exporter) | ||
metric_provider = MeterProvider(metric_readers=[metric_reader], resource=resource) | ||
metrics.set_meter_provider(metric_provider) | ||
return metric_provider | ||
|
||
|
||
def _setup_otel_tracing(resource, multiprocessing=False): | ||
otlp_exporter = OTLPSpanExporter() | ||
def _setup_otel_tracing(resource, multiprocessing=False, session=None): | ||
otlp_exporter = OTLPSpanExporter(session=session) | ||
trace_provider = TracerProvider(resource=resource) | ||
if multiprocessing: | ||
trace_provider.add_span_processor(SimpleSpanProcessor(otlp_exporter)) | ||
|
@@ -225,8 +227,18 @@ def setup_otel(runtime_parameters, options): | |
# (most frequent case) | ||
multiprocessing = options.max_workers > 1 | ||
|
||
pool_maxsize = 30 # reqeusts default is 10 | ||
if runtime_parameters.has("DR_OTEL_SESSION_POOL_MAXSIZE"): | ||
pool_maxsize = int(runtime_parameters.get("DR_OTEL_SESSION_POOL_MAXSIZE")) | ||
|
||
session = requests.Session() | ||
adapter = requests.adapters.HTTPAdapter(pool_maxsize=pool_maxsize) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably need timeout There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exporter already has timeout config that they pass into session, can be configured by env var: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default timeout is 10 sec. |
||
session.mount("http://", adapter) | ||
session.mount("https://", adapter) | ||
resource = Resource.create() | ||
trace_provider = _setup_otel_tracing(resource=resource, multiprocessing=multiprocessing) | ||
trace_provider = _setup_otel_tracing( | ||
resource=resource, multiprocessing=multiprocessing, session=session | ||
) | ||
|
||
logger_provider = None | ||
metric_provider = None | ||
|
@@ -235,8 +247,10 @@ def setup_otel(runtime_parameters, options): | |
if runtime_parameters.has("DR_OTEL_METRICS_LOGS_ENABLED") and runtime_parameters.get( | ||
"DR_OTEL_METRICS_LOGS_ENABLED" | ||
): | ||
logger_provider = _setup_otel_logging(resource=resource, multiprocessing=multiprocessing) | ||
metric_provider = _setup_otel_metrics(resource=resource) | ||
logger_provider = _setup_otel_logging( | ||
resource=resource, multiprocessing=multiprocessing, session=session | ||
) | ||
metric_provider = _setup_otel_metrics(resource=resource, session=session) | ||
|
||
log.info(f"OTEL is configured with endpoint: {endpoint}") | ||
return trace_provider, metric_provider, logger_provider | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about
total_concurrent_requests = 500
num_workers = self._params.get("processes")
pool_maxsize = ceil(total_concurrent_requests / num_workers)
for 8 cores it is ~60