-
Notifications
You must be signed in to change notification settings - Fork 96
Trouble Batching Data #166
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
Comments
@eric-w-dyn, thanks for using this client. I don't see a big problem in your code. All points should be written unless there is an error. How do you check data? Few points to improve:
if (!client.flushBuffer()) {
Serial.print("InfluxDB flush failed: ");
Serial.println(client.getLastErrorMessage());
}
// Uncomment bellow in case of a problem and rebuild sketch
#define INFLUXDB_CLIENT_DEBUG_ENABLE
#include "util/debug.h" |
@vlastahajek Thanks for the tips. I think I got batching working properly. However, I'm still not happy for the results that I'm getting. Do you have any configuration tips to minimize the time it take to flush the batch? I'm collecting data from an analog sensor at 80Hz, thus I would like to write a continuous stream to InfluxDB at 80Hz. I'm getting about 80Hz within each batch, but there are relatively long gaps between each batch where I lose information. I have attached a screenshot of my Grafana dashboard that shows these gaps. |
@eric-w-dyn, when writing data less more then 2 per minute, you should set HTTP reuse: client.setHTTPOptions(HTTPOptions().connectionReuse(true); if you gather data at a different time than adding points, keep time for it. If you will still encounter a lag, please enable debug and post the debug output here. |
@vlastahajek I already had HTTP reuse enabled. And yes, I am syncing with a time server to ensure the points have the correct time. Here is some output from debug:
|
The log shows it takes nearly 4s to write a batch. And this is the gab shown in the chart when you are not reading data. Try sending smaller batches more frequently. But you will still get gaps. As you want to read 80Hz data and you are using ESP32, I would suggest reading a sensor on core 0 (using |
Yeah, I've tried splitting tasks into different cores a little already, but haven't yet reached a working program. My understanding is that ESP32 should already split networking tasks into a different core by default. Perhaps I am misled in that understanding... |
My understanding is that core 0 is used for radio (WiFi, BLE) management, not networking. I have a custom 433Mhz ASK sensors network. ESP32 acts as a gateway that writes data from sensors to a database. As writing takes time and had to put the radio receiving task to core 0 to don't miss 433MHz radio packets. Where do have the server? I tried your use case and when I have a server on rpi on the same network, it's written almost instantly. Such long times are usually on remote SSL server (e.g. AWS) If nothing changes in your setup to speed up writing, as sending 80 lines takes 4s (total roundtrip), you won't be able to write it at such speed. Even you will create data on core 0, writing takes so long that writing task will be a lot slower than reading task. |
My InfluxDB database is just local on my computer. Everything stays local. I'll try |
If you have a server on the local computer, writing shouldn't be a problem. No more than 100ms, which should be sufficient for you use case. If writing takes seconds, there must be a problem somewhere else. uint32_t d = millis();
if (!client.writePoint(sensorCosine)) {
Serial.print("InfluxDB write failed: ");
Serial.println(client.getLastErrorMessage());
}
d = millis()-d;
if(i==99) {
Serial.printf("Sending took %dms\n", d);
} |
The debug output If you have milliseconds precicion, some points will be overwritten because of the same timestamp, as writting to buffer is fast. You don't need to call Actually, maximum supported batch size is 255 and higher number are trimmed to this. It is due to memory restrictions, mainly on ESP8266 device. Regular points are usually long (several tags and fields), so this limit is set to prevent OOM crash. |
Oh ok. I wasn't aware that 255 was the max batch size. I remember reading somewhere that the optimal batch size for Influx is 2000, but it must not be applicable in my situation. Since ESP32 has more memory, is it possible to change the library code to increase the maximum support batch size? |
If fact, recommended bachsize is 5000. However this is meant for normal computer/server, not embeded device. |
I have struggled with this also. I have a high data rate application with 8k sample rate on esp32 reading vibration data with external psram and did a custom implementation for buffering to it. However the overhead is too big when sending packets even when queuing from the external buffer and for some reason I encounter random crashes when I still have heap space, I guess line protocol just isn't good for this. Can you recommend a binary alternative of it, I've tried looking up the header specifications for influx to do something, but it's pretty hard. |
I’ve had better success recently using Bluetooth rather than Wifi. I’m using Python with the Bleak library to ingest the data into Influx. I can get close to 1kHz sample rate with no batching |
Internet communication is required in this project. The main issue with line protocol here is the use of strings in multiple buffers and then they are copied in the tcp packet buffer again from what I reckon, that's a lot of overhead when you have a lot of points. I guess a tcp packet can't be build as a stream of strings to create it while sending it sequentially in order to save resources, or isn't implemented. Best option is to send binary data and I would have preferred to send directly to the db with this, tried with mqtt before but had some problems configuring the broker with the latest telegraf server. Another potential solution would be if I try to patch this lib to use the psram directly for its buffers, I'm not sure that would help either considering the overhead. |
I have good news for you. |
I was away for the holidays, will go testing it 👍. This feature should be mainstream |
I've followed many examples and instructions in this repository, but am still having issues batching data.
My situation: I’m currently using an ESP32 iOT microcontroller to collect some data and am sending the data to a local InfluxDB server for storage. I’m using the Arduino InfluxDB client to connect the microcontroller to the database and am wanting to batch my data to increase my sample rate. I’ve looked at batching examples and instructions on GitHub but it doesn’t seem to work. In my testing, I can either only get the data to come in synchronously or it doesn’t make it into InfluxDB at all.
Here is my code, in case it is helpful:
The text was updated successfully, but these errors were encountered: