From 0696cf54ee22848d1b09d60290ca01e46c60aa66 Mon Sep 17 00:00:00 2001 From: Witek Bedyk Date: Tue, 21 Jan 2020 10:18:22 +0100 Subject: [PATCH] Add configuration option influxdb.batch_size The new configuration option is used to control the maximum size of batches written to InfluxDB and optimizes performance for high loads. The default value is set to 10 000 data points per batch. Change-Id: I82c3e4e64984a996e41fe2657ce36b032b40d3fd Story: 2007191 Task: 38319 --- monasca_persister/conf/influxdb.py | 3 +++ .../repositories/influxdb/abstract_repository.py | 4 +++- .../notes/add_influxb_batch_size-01b7a476b6bd8a81.yaml | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/add_influxb_batch_size-01b7a476b6bd8a81.yaml diff --git a/monasca_persister/conf/influxdb.py b/monasca_persister/conf/influxdb.py index f0fef3a0..1f3020e7 100644 --- a/monasca_persister/conf/influxdb.py +++ b/monasca_persister/conf/influxdb.py @@ -27,6 +27,9 @@ influxdb_opts = [ help='Default retention period in hours for new ' 'databases automatically created by the persister', default=0), + cfg.IntOpt('batch_size', + help='Maximum size of the batch to write to the database.', + default=10000), cfg.HostAddressOpt('ip_address', help='Valid IP address or hostname ' 'to InfluxDB instance'), diff --git a/monasca_persister/repositories/influxdb/abstract_repository.py b/monasca_persister/repositories/influxdb/abstract_repository.py index ccc69a66..90aace7e 100644 --- a/monasca_persister/repositories/influxdb/abstract_repository.py +++ b/monasca_persister/repositories/influxdb/abstract_repository.py @@ -52,9 +52,11 @@ class AbstractInfluxdbRepository(abstract_repository.AbstractRepository): # NOTE (brtknr): Loop twice to ensure database is created if missing. for retry in range(2): try: + batch_size = self.conf.influxdb.batch_size self._influxdb_client.write_points(data_points, 'ms', protocol='line', - database=database) + database=database, + batch_size=batch_size) break except influxdb.exceptions.InfluxDBClientError as ex: # When a databse is not found, the returned exception resolves diff --git a/releasenotes/notes/add_influxb_batch_size-01b7a476b6bd8a81.yaml b/releasenotes/notes/add_influxb_batch_size-01b7a476b6bd8a81.yaml new file mode 100644 index 00000000..8eeb5133 --- /dev/null +++ b/releasenotes/notes/add_influxb_batch_size-01b7a476b6bd8a81.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Configuration option `batch_size` for InfluxDB to control the maximum + size of batches written to the database. Default value set to 10 000 data + points.