|
| 1 | += Timedata Aggregated InfluxDB |
| 2 | + |
| 3 | +OpenEMS Backend implementation for aggregated InfluxDB access. |
| 4 | + |
| 5 | +[NOTE] |
| 6 | +==== |
| 7 | +Bundle is needed for highly optimized environments with |
| 8 | +thousands of connected edges only. If you do not need that functionality you can skip this chapter. |
| 9 | +==== |
| 10 | + |
| 11 | +A large number of OpenEMS edges connected to a single backend leads to a performance bottleneck. |
| 12 | +The bottleneck is mainly due to the access to the database. This `Aggregated InfluxDB` bundle in |
| 13 | +combination with the xref:../io.openems.backend.timedata.influx.adoc[Timedata Influx] |
| 14 | +bundle can mitigate this bottleneck. This happens by writing all data as usual via xref:../io.openems.backend.timedata.influx.adoc[Timedata Influx] into |
| 15 | +an Influx database (`DB 1`). Furthermore, all "aggregated data" (see xref:timedata.adoc[edge datatypes]) are written via the `Aggregated InfluxDB` bundle to |
| 16 | +another database (`DB 2`) located on another server. |
| 17 | +Thus `DB 1` holds all data in high resolution, while `DB 2` only holds very few data (5-minute averages for power values |
| 18 | + or only daily values for energy). Furthermore, a retention policy of e.g. 90 days is applied to `DB 2`. |
| 19 | +Thus `DB 1` provides relatively slow access to a huge amount of data |
| 20 | +and `DB 2` provides fast and responsive access to a relatively small database. |
| 21 | + |
| 22 | +Within OpenEMS backend access to both databases is managed by the |
| 23 | +https://github.com/OpenEMS/openems/blob/develop/io.openems.backend.core/src/io/openems/backend/core/timedatamanager/TimedataManagerImpl.java[TimedataManager]. |
| 24 | +The TimedataManager writes edge relevant data to **all** Timedata providers, |
| 25 | +whereas it reads data only from the **first** Timedata provider, |
| 26 | + which can deliver. |
| 27 | +Assuming correct configuration, TimedataManager first returns historical data |
| 28 | +from `DB 2` (fast and responsive). |
| 29 | +And only in a very few cases it gets the data from `DB 1` |
| 30 | +(probably slower). |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | +[CAUTION] |
| 36 | +==== |
| 37 | +The `Timedata.AggregatedInfluxDB` includes a class `AllowedChannels.java`. |
| 38 | +This implementation includes a *hardcoded* list of channels: |
| 39 | +
|
| 40 | +* `ALLOWED_AVERAGE_CHANNELS` are used to calculate the 5min average values (e.g. average power values). |
| 41 | +* `ALLOWED_CUMULATED_CHANNELS` are used to calculate daily values (e.g. energy values). |
| 42 | +
|
| 43 | +This list must be adopted to a concrete usecase. It strongly depends on |
| 44 | +
|
| 45 | +* your strategy to select component-IDs. |
| 46 | +* the components you are using within OpenEMS. |
| 47 | +
|
| 48 | +If you detect some widgets within your OpenEMS-UI which hava empty values, |
| 49 | +it may have to do with an incorrect hardcoded list. |
| 50 | +
|
| 51 | +==== |
| 52 | + |
| 53 | +== Configuration Setup |
| 54 | + |
| 55 | +If you expect your backend to handle thousands of connected edges, |
| 56 | +the following configuration may provide a good start setup: |
| 57 | + |
| 58 | +*Create database and set retention policy:* |
| 59 | + |
| 60 | +Before starting the OpenEMS backend and after intially setting up the influx servers, |
| 61 | +you need to create the databases `influx0` and `aggregated0` |
| 62 | +and some retention policies: |
| 63 | + |
| 64 | +[source,shell] |
| 65 | +---- |
| 66 | +
|
| 67 | +##### Influx Server 1 ##### |
| 68 | +curl -i -XPOST http://127.0.0.1:8082/query --data-urlencode "q=CREATE DATABASE influx0" |
| 69 | +
|
| 70 | +##### Influx Server 2 ##### |
| 71 | +curl -i -XPOST http://127.0.0.1:8081/query --data-urlencode "q=CREATE DATABASE aggregated0" |
| 72 | +
|
| 73 | +curl -i -XPOST http://127.0.0.1:8081/query --data-urlencode "q=CREATE RETENTION POLICY rp_max ON aggregated0 DURATION 90d REPLICATION 1" |
| 74 | +curl -i -XPOST http://127.0.0.1:8081/query --data-urlencode "q=CREATE RETENTION POLICY rp_avg ON aggregated0 DURATION 90d REPLICATION 1" |
| 75 | +
|
| 76 | +---- |
| 77 | + |
| 78 | +*OpenEMS backend configuration:* |
| 79 | + |
| 80 | +* bundle `Timedata.AggregatedInfluxDB` |
| 81 | + ** ComponentID: `timedata0` |
| 82 | + ** QueryLanguage: `INFLUX_QL` |
| 83 | + ** URL: http://127.0.0.1:8081 |
| 84 | + ** Apikey: `influxuser:influxpassword` |
| 85 | + ** Bucket: `aggregated0` |
| 86 | + ** Retention policy for avg values: `rp_avg` |
| 87 | + ** Retention policy for max values: `rp_max` |
| 88 | + ** Measurement Avg: `avg` |
| 89 | + ** Measurement for max values: `Europe/Berlin=max` |
| 90 | + |
| 91 | +* bundle `Timedata.InfluxDB` |
| 92 | + ** ComponentID: `timedata1` |
| 93 | + ** QueryLanguage: `INFLUX_QL` |
| 94 | + ** URL: http://127.0.0.1:8082 |
| 95 | + ** Org: `-` |
| 96 | + ** Apikey: `influxuser:influxpassword` |
| 97 | + ** Bucket: `influx0/autogen` |
| 98 | + ** Measurement: `data` |
| 99 | + |
| 100 | +* bundle `Core Timedata-Manager` |
| 101 | + ** Timedata-IDs: `[timedata0, timedata1]` |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | +[NOTE] |
| 107 | +==== |
| 108 | +* Note the different Bucket namings, one with retention policy `autogen` and one without. |
| 109 | +* Make sure that your influx databases are located on two different servers |
| 110 | +or that you can easily move one database to another server later. |
| 111 | +* Be sure that the sequence within the `Core Timedata-Manager` is |
| 112 | +configured correctly - the component-ID of the `Timedata.AggregatedInfluxDB` |
| 113 | +comes first. |
| 114 | +* Influx Database must have at least Version 1.8.10. |
| 115 | +* Take care of your edge to backend connections on the edge side. Be sure to understand and select the right `PersistencePriority` for the different datatypes. |
| 116 | +* Remember the hardcoded list in _AllowedChannels.java_ |
| 117 | +* Note that you can shift the load of your databases by choosing different retention policies. |
| 118 | +* Be sure you know exactly how Influx handles *reading* and *writing* data when using different retention policies on one database. |
| 119 | +==== |
| 120 | + |
| 121 | + |
| 122 | +https://github.com/OpenEMS/openems/tree/develop/io.openems.backend.timedata.influx.aggregatedinflux[Source Code icon:github[]] |
0 commit comments