26 August 2024: Major update for Gladys!

Hello everyone!

For those who haven’t followed this topic, I’ve been working since the end of June on a major update to Gladys.

This update will change how historical sensor values are stored in Gladys, moving from storage in an OLTP database (SQLite) to an OLAP database (DuckDB).

We keep SQLite for all relational data (users, home, scenes, etc.), it’s only the sensor values that will be stored in DuckDB.

Concretely, this update will offer all users:

  • Much smaller databases. @GBoulvin went from an 11 GB database to 65 MB with DuckDB, for 11 million stored states. This is possible because these two database systems don’t work at all the same way, and DuckDB aggressively compresses time-series data.
  • Accurate and ultra-fast graphs, even over long periods. No more imprecise aggregated data from Gladys; it is now possible to make graphs over long durations, mixing old data and live values from a sensor, which wasn’t possible until now!
  • Better overall Gladys performance: no more hourly data aggregation processes that used disk bandwidth on small machines.

Why wait until now to move to this revolutionary system?

DuckDB is the only file-based OLAP database on the market.

Until now, DuckDB was in alpha/beta, and each version still brought breaking changes, which wasn’t compatible with our need for stability in Gladys.

In June 2024, DuckDB reached 1.0 (stable), and I immediately started the work to move to this system.

Next steps

I’ve already installed this version on my instance at home since the beginning of the week to check that everything is fine, and so far everything is going perfectly.

If everything continues like this, I’ll release this version on Monday, August 26 :rocket:

Migrate now?

If you’re comfortable with the command line, and you want to migrate to this version right now, you can! (And give me feedback).

The Docker image is available at this address:

gladysassistant/gladys:duckdb

You can pull this version:

docker pull gladysassistant/gladys:duckdb

Then stop your existing Gladys container:

docker stop gladys \u0026\u0026 docker rm gladys

Then start a Gladys container with the DuckDB image:

docker run -d \\
--log-driver json-file \\
--log-opt max-size=10m \\
--cgroupns=host \\
--restart=always \\
--privileged \\
--network=host \\
--name gladys \\
-e NODE_ENV=production \\
-e SERVER_PORT=80 \\
-e TZ=Europe/Paris \\
-e SQLITE_FILE_PATH=/var/lib/gladysassistant/gladys-production.db \\
-v /var/run/docker.sock:/var/run/docker.sock \\
-v /var/lib/gladysassistant:/var/lib/gladysassistant \\
-v /dev:/dev \\
-v /run/udev:/run/udev:ro \\
gladysassistant/gladys:duckdb

(Don’t forget to modify this command for your personal case)

Then you will be able to see the migration status on your dashboard.

And once the migration is finished, you will be able to delete the old SQLite states in Settings -\u003e « System » of Gladys:

Note: You will of course need to switch back to the image gladysassistant/gladys:v4 once the update is deployed!

If you want to wait a bit

If you’re not at home on August 26 and you want to avoid the update happening automatically while you’re away, you can pause Watchtower until then and restart Watchtower when you return, which will save you from potential problems you couldn’t fix remotely.

I’m not opposing SQLite and DuckDB

SQLite is a great tool, which we continue to use in Gladys.

However, for the specific use case we have (time-series data storage), DuckDB is much better suited.

For the rest of the tables, SQLite remains the best solution on the market for our use, and I’m still a believer in SQLite!

So I’m not at all opposing these two databases, they are two radically different products :slight_smile:

Thanks to those who will test it, I’m really looking forward to seeing this new tech in your hands!

4 Likes

Migration in progress!

image

For my part, the database is 20 GB
image

2 Likes

27 million!! Incredible :star_struck:

Can’t wait to see it, keep us posted here

Migration completed in just under 1 hour

Before 20GB
image

With DuckDB 119MB. Incredible difference
image

3 Likes

And the purge?

In progress!
image

1 Like

Awesome, I’ll probably get started on the 26th, but before that I need to debug my disconnects lol.

Great post in any case, very clear and informative!! :+1:

1 Like

However, the purge is taking a long time…
Fortunately Gladys is still operational

Yes, that’s intentional! It deletes 1000 lines at a time, otherwise it would block the disk too much and so your Gladys wouldn’t be available during the purge :slight_smile:

1 Like

Hello,

Migration in progress for me with a 5.2 GB database

image

However I don’t have access to the tracking on the dashboard and I have this in the tasks:

Could you give the commands @pierre-gilles please? So on 26/08? :
(It’s more to avoid making a mistake than anything else :slight_smile: )
image

I suppose it’s:

docker pull gladysassistant/gladys:v4
docker stop gladys \u0026\u0026 docker rm gladys

Then restart a Gladys container with the V4 image:

docker run -d \\
--log-driver json-file \\
--log-opt max-size=10m \\
--cgroupns=host \\
--restart=always \\
--privileged \\
--network=host \\
--name gladys \\
-e NODE_ENV=production \\
-e SERVER_PORT=80 \\
-e TZ=Europe/Paris \\
-e SQLITE_FILE_PATH=/var/lib/gladysassistant/gladys-production.db \\
-v /var/run/docker.sock:/var/run/docker.sock \\
-v /var/lib/gladysassistant:/var/lib/gladysassistant \\
-v /dev:/dev \\
-v /run/udev:/run/udev:ro \\
gladysassistant/gladys:v4

Thanks :slight_smile:

Edit:

Success:
image

I would just like confirmation from @pierre-gilles before starting the purge step :slight_smile:

Edit 2:

Silly me :laughing: I needed to go local and not on Gladys Plus:

Migration completed in 15 minutes :wink:

I’m starting the purge

image

After one hour everything is OK:
image

I’m starting the cleanup:
image

The database is now over 38 MB:
image

And the Gladys Plus backup:

1 Like

Thanks for testing @prohand !

Yes that’s what you provided :slight_smile:

For the Docker command it’s the same as on Installation avec Docker | Gladys Assistant

Yes! Gladys Plus doesn’t have the DuckDB version yet, it’s not in production yet :wink:

Awesome :star_struck: Another success!

1 Like

That’s great!
As for me, I haven’t tested it, I moved to another country, and I haven’t unpacked all the boxes yet. New house, new setup to redo and probably a new Gladys instance to come.
I can’t wait to try it :hugs:

3 Likes

Enjoy settling in!

1 Like

@lmilcent Enjoy settling in :smiley:

1 Like

Works perfectly for me, no problem
the only hitch is when I switched back to the image gladysassistant/gladys:v4 as indicated above.
there are no more comments

Perfect @Marco85, thanks for testing! Oh no, you absolutely must not switch back to the v4 image right away :sweat_smile: Switch immediately to the DuckDB image!!

You should only switch back to the v4 image when I’ve put this development into production, on August 26 :slight_smile:

ok it’s fine, I switched back to the DuckDB image

1 Like

Nice setup @imilcent,

I’m taking this opportunity to ask which type of probe you use for refrigerators and freezers. I seem to remember that with regular thermometers you used a lot of batteries.

Thanks in advance

1 Like

@pierre-gilles,
Regarding the part:

Would it be possible to format Math.abs with an additional condition on the feature type as well, because I end up with ugly curves when, for example, the wind is weak:

The same will apply to distance sensors, I suppose.

Indeed! I’ll note that.

1 Like