Skip to content
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

feat: implement lz4 compression #204

Merged
merged 7 commits into from
May 5, 2023
Merged

feat: implement lz4 compression #204

merged 7 commits into from
May 5, 2023

Conversation

de-sh
Copy link
Member

@de-sh de-sh commented Apr 17, 2023

Closes #

Add lz4 compression as a feature of uplink, decompression is already supported by beamd, other schemes can also be implemented once there are suitable de-compressor implementations on the beamd side.

Changes

Uplink now pushes data onto the same topic with an appended /lz4 to indicate the payload is compressed with the lz4 scheme.
Compression is an opt-in feature per-stream and can be configured as follows(underlying usage of enums is done to support multiple schemes in the future, currently only Lz4 compression is supported):

[streams.imu]
topic = "{stream_prefix}/imu/jsonarray"
buf_size = 100
compression = "Lz4"

Why?

Allows for much less network bandwidth use

Trials Performed

Pushing simulator device_shadow onto stage compressed with lz4 and checking it's presence within clickhouse proving that the compressed payload was decompressed and written into the database by beamd.

uplink

  2023-04-17T18:26:11.182976Z DEBUG uplink::base::serializer: publishing on /tenants/demo/devices/615/events/device_shadow/jsonarray/lz4 with size = 198

clickhouse

SELECT *
FROM demo.device_shadow
WHERE id = '615'

Query id: 121d6f56-f33f-4de0-8dca-c54ac9edc7f2

┌─id──┬───────date─┬────────insert_timestamp─┬───────────────timestamp─┬─sequence─┬─Status─┬─mode─┬─firmware_version─┬─config_version─┬─distance_travelled─┬─range─┬───────────────SOC─┐
│ 615 │ 2023-04-17 │ 2023-04-17 18:26:04.070 │ 2023-04-17 18:26:02.164 │        1 │        │ off  │ v0.5.0           │ v0.0.1         │              20996 │ 55350 │ 69.28193333238939 │
│ 615 │ 2023-04-17 │ 2023-04-17 18:26:04.070 │ 2023-04-17 18:26:03.166 │        2 │        │ on   │ v0.5.0           │ v0.0.1         │              24116 │ 55584 │ 86.21089455625196 │
│ 615 │ 2023-04-17 │ 2023-04-17 18:26:09.250 │ 2023-04-17 18:26:04.168 │        3 │        │ off  │ v0.5.0           │ v1.0.1         │              25632 │ 58195 │ 80.41426772590029 │
│ 615 │ 2023-04-17 │ 2023-04-17 18:26:09.250 │ 2023-04-17 18:26:05.171 │        4 │        │ off  │ v1.0.1           │ v0.5.0         │              27024 │ 57536 │ 53.59811156317747 │
│ 615 │ 2023-04-17 │ 2023-04-17 18:26:09.250 │ 2023-04-17 18:26:06.174 │        5 │        │ off  │ v0.5.0           │ v1.0.1         │              22526 │ 58720 │ 78.36922772614193 │
│ 615 │ 2023-04-17 │ 2023-04-17 18:26:09.250 │ 2023-04-17 18:26:07.176 │        6 │        │ off  │ v1.0.1           │ v1.0.1         │              22211 │ 50614 │ 87.85481786393973 │
│ 615 │ 2023-04-17 │ 2023-04-17 18:26:09.250 │ 2023-04-17 18:26:08.178 │        7 │        │ off  │ v1.0.1           │ v0.0.1         │              27612 │ 54864 │ 82.69632161021516 │
│ 615 │ 2023-04-17 │ 2023-04-17 18:26:09.250 │ 2023-04-17 18:26:09.179 │        8 │        │ on   │ v0.5.0           │ v0.5.0         │              28849 │ 52489 │ 87.15308145723989 │
│ 615 │ 2023-04-17 │ 2023-04-17 18:26:14.427 │ 2023-04-17 18:26:10.181 │        9 │        │ on   │ v0.5.0           │ v0.5.0         │              25700 │ 59629 │ 86.19682304368897 │
│ 615 │ 2023-04-17 │ 2023-04-17 18:26:14.427 │ 2023-04-17 18:26:11.182 │       10 │        │ off  │ v1.0.1           │ v0.5.0         │              27896 │ 56765 │ 70.88746508045541 │
└─────┴────────────┴─────────────────────────┴─────────────────────────┴──────────┴────────┴──────┴──────────────────┴────────────────┴────────────────────┴───────┴───────────────────┘

@de-sh de-sh requested a review from tekjar April 17, 2023 18:47
* feat: configuring per-stream compressibility

* doc: explain `is_compressible` config

* feat: compression as an enum

* fix: remove global `enable_compression`

* refactor: `compress` ~> `lz4_compress`
@de-sh de-sh changed the base branch from main to next May 1, 2023 13:03
@de-sh de-sh merged commit 5e350f7 into next May 5, 2023
@de-sh de-sh deleted the lz4 branch May 5, 2023 05:43
de-sh added a commit that referenced this pull request May 15, 2023
* feat: implement lz4 compression (#204)

* feat: implement lz4 compression

* fix: compression should be opt-in

* feat: allow configuring compressibility per-stream (#209)

* feat: configuring per-stream compressibility

* doc: explain `is_compressible` config

* feat: compression as an enum

* fix: remove global `enable_compression`

* refactor: `compress` ~> `lz4_compress`

* fix: broken merge

* feat: allow configuring per-stream persistability (#207)

* feat: allow configuring non-persistent streams

* doc: add example config for non-persistent stream

* fix: serializer test

* fix: `is_persistable` ~> `persistance`

* fix: normal ~> slow even if non-persistable data

* fix: logs are always persisted

* Merge branch 'next' into non-persist

* fix: use compressed stream topic as is from config (#230)

* feat!: per-stream persistence to disk (#229)

* Guard log config in mac

* Extract some methods into persistence struct

* Finish storage module with optional persistence

* feat: use `storage` instead of `disk` (#223)

* fix: ensure test run successfully

* feat: `use storage` not `disk`

* feat: restructure persistence config and use

* fix: serializer tests

* refactor: remove old `disk`

* feat: trace lost segment with debug log

* style: clippy suggestion

* fix: load previously persisted files

* fix: comment out unused code

* refactor: simplify serializer test

* feat: add test to ensure files removed post flush (#228)

* fix: add partial read file presence check

* feat: completely per-stream persistance

* fix: serializer metrics

* doc: explain persist/compress configs

* refactor: stream topic

* fix: ensure all backlogs are cleared on catchup

* refactor: unnecessary result

* fix: default to `MAX_BUFFER_SIZE`

* fix: add missing import

* fix: append stream name to path in persistence

* refactor: `StorageHandler`

* fix: finish merge

* doc: persistence config change

* fix: remove unncessarily included config variable

* fix: metrics updation

* refactor: `StorageHandler.next()` returns `Option`

---------

Co-authored-by: tekjar <[email protected]>

* style: clippy suggestion

---------

Co-authored-by: Devdutt Shenoi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant