Hi experts,
recently I used my 1st task in influxdb and it was the 1st time I used Flux.
Obviously I miss some experience to set the task up in a proper way.
I noticed the following:
- The task runs each 5 mins. Usually it runs for 0.7 … 0.8 s (according to the influxdb UI). I feel that’s already quite long, but roughly each hour it runs for 10 … 13 s (!).
- The memory consumption of the server, which was around 550 MB all the time before increased up to 1 GB since the task runs. And it’s fluctuating.
- I have installed the same task 1st on kind of a test server, where influxdb and some other tools (grafana, telegraf, traefik) runs in docker containers. Here the task runs only for 0.02 … 0.04 s and I can’t the see the dramatic increase in run time each hour or so. There is no noticeable increase of memory use.
- The main difference between the main server and the test server is, that the main server has much more historical data.
My idea was that the task only runs ones on historical data when it is started for the 1st time. Afterwards I hoped it will only process new data that has arrived since the last run. I’m using tasks.lastSuccess()
function to achieve that (actually ChatGPT recommended it ).
But I assume that didn’t work out for some reasons and the task is procesing all historic data in each run. Still I do not know, why it sometimes takes even much longer (10 … 20 times longer !).
And here is the task’s code:
import "influxdata/influxdb/tasks"
option task = {name: "calcLevel", every: 5m}
from(bucket: "<bucket-name>")
|> range(start: tasks.lastSuccess(orTime: 2024-06-01T00:00:00Z))
|> filter(fn: (r) => r._measurement == "source_measurement" and r._field == "distance")
|> map(
fn: (r) =>
({r with _time: r._time,
_measurement: "destination_measurement",
_field: "level",
_value:
// calculate new "level"-value based on the device that produced the in-value
if r.deviceName == "device_1" then
163.5 - r._value / 10.0
else if r.deviceName == "device_2" then
183.5 - r._value / 10.0
else if r.deviceName == "device_3" then
193.0 - r._value / 10.0
else
float(v: 0.0),
}),
)
// write new "level"-value to the same bucket
|> to(bucket: "<bucket-name>")
Can someone tell what I did wrong?
Thank you very much!
Christian