GreptimeDB 的车云一体方案已成功应用于头部新能源车企,解决了毫秒级信号的采集、存储和分析问题,为企业带来了显著的降本增效成果 ——数据的流量和存储成本更低,数据分析更实时。
但是为了更加全面地评估 GreptimeDB 在嵌入式和边缘计算环境中的性能, 我们将其与 SQLite 进行了详细的对比测试。本次测试的目的是评估它们在类似应用场景中的数据处理性能,以验证 GreptimeDB 在物联网,车联网和可观测应用环境中的适应性和优势。
SQLite 是一个小巧、快速并且功能齐全的 SQL 数据库引擎,它被认为是世界上使用最广泛的数据库系统,能够部署在各类移动设备(比如手机、机顶盒、电视)及嵌入到本地应用程序中等等。
本文将对比 GreptimeDB 和 SQLite 在高通骁龙 8155 智能座舱芯片平台上的性能表现,包括读写性能、资源占用和压缩率等。
| Chipset (芯片版本) | Qualcomm Technologies, Inc SA8155P |
| Memory(内存) | 12 GB |
| Storage(存储) | eMMC NAND Flash |
| GreptimeDB Edge | v1.0 商用版 |
| SQLite | 3.46.0,基于 rusqlite 包装 https://github.com/rusqlite/rusqlite |
两者都关闭 WAL,默认关闭 GreptimeDB Edge,通过下列命令关闭 SQLite 的 journal 和同步写入:
PRAGMA journal_mode=
OFF;
PRAGMA
synchronous=
OFF;
其他都为默认配置。
我们同样采用 TSBS 生成的 CPU 监控数据,总共 1000 万行,每行数据有 10 个 Tag 和 Field,加上时间戳,总共 21 个列,样例数据如下:
cpu,hostname=host_0,region=eu-central
-1,datacenter=eu-central
-1a,rack=
6,os=Ubuntu15
.10,arch=x86,team=SF,service=
19,service_version=
1,service_environment=test usage_user=
58i,usage_system=
2i,usage_idle=
24i,usage_nice=
61i,usage_iowait=
22i,usage_irq=
63i,usage_softirq=
6i,usage_steal=
44i,usage_guest=
80i,usage_guest_nice=
38i
1686441600000000000
❝建表语句参考附录。SQLite 只对
hostname和ts列做主键索引,这两个列是查询需要,没有将其他 tag 列加入到主键,因为写入性能会非常差。GreptimeDB 索引了所有 tag 列,ts是TIME INDEX约束,并启用了 append 模式。
sqlite3_step 执行,批次大小设置为 32,经过测试,使用更大的批大小对整体吞吐影响不大。

(GreptimeDB Edge 基于共享内存的写入更高效)
写入 1000 万行后执行 SQL 查询,我们从 TSBS 查询场景中挑选了 7 条 SQL 执行,覆盖典型场景,具体见附录。
由于 SQLite 并不支持多线程的并发写入 ,我们测试了单核极限写入场景:
GreptimeDB 写入 TPS 大概是 SQLite 的 1.7 倍,达到 7.2 万行每秒。
我们单独测试了 GreptimeDB 的并发写入性能,在平均 160% CPU 消耗并且将 I/O(Input/Output) 打满的情况下,达到了 10 万行每秒的写入性能。
除了写入性能外,嵌入式数据库的磁盘占用同样值得关注。由于嵌入式设备往往存储空间并不是很充裕,而且其所使用的存储介质通常为 Flash 闪存,因此如果磁盘占用过大,不仅会导致能够保存的数据量受限,而且会大大缩短存储介质的寿命。在本次测试中,我们将 1000 万行数据全部写入到 GreptimeDB 和 SQLite 后,分别测量两者数据目录所占用的大小。
得益于 GreptimeDB Edge 所使用的列式存储的极高的压缩率,最终其所占用空间仅为 87MB,而 SQLite 需要 1,686 MB, GreptimeDB 的压缩率是 SQLite 的 19 倍。
我们将写入限流为 43000 行每秒,测量下 GreptimeDB 和 SQLite 的 CPU 和内存占用:

结论:
我们选取了 7 条典型 SQL 的查询结果如下(查询耗时,单位:毫秒):
| 查询场景 | SQLite | GreptimeDB | 查询场景说明 |
| FIVE_MINUTE_1 | 1 | 33 | 查询 1 个主机最近 5 分钟所有指标数据 |
| COUNT | 252 | 11 | 统计总行数 |
| CPU_MAX_ALL_1 | 16 | 52 | 查询 1 个主机 8 个小时内每小时所有 CPU 指标的最大值 |
| CPU_MAX_ALL_8 | 119 | 78 | 查询 8 个主机 8 个小时内每小时所有 CPU 指标的最大值 |
| SINGLE_GROUP_BY_1_1_1 | 145 | 105 | 查询 1 个主机 1 个小时内 1 个 CPU 指标每分钟的最大值 |
| LAST_POINT_ALL | 1246 | 1860 | 所有主机的最新一行数据 |
| LAST_POINT_ONE | 118 | 140 | 1 个主机的最新一行数据 |
可以看到,SQLite 的查询性能相当出色,而 GreptimeDB Edge 也没有明显落后,并且在时序聚合查询场景更快。
在高通 8155 芯片平台上, GreptimeDB Edge 的写入性能是 SQLite 的 1.7 倍,数据压缩率是 SQLite 的 19 倍,查询性能在时序聚合场景更优,资源占用方面 CPU 消耗更低,内存消耗较大,但是可以通过配置灵活地在 CPU、内存和压缩率三者之间分配。
本测试使用的 GreptimeDB Edge 商用版还是 1.0 版本, 最新研发的 2.0 版本将支持日志引擎、轻量级流计算引擎 Flow 以及专为嵌入式 LLM 应用设计的向量检索的能力,并且在读写性能和资源占用做出进一步的优化。 Greptime 边云一体方案显著降低数据的流量和存储成本,赋能边缘计算,并在边云之间灵活协调算力。
如果您对 GreptimeDB Edge 商用版在智能汽车等边缘环境的使用感兴趣,欢迎联系我们做进一步的交流 (Wechat: z303036724 / greptime )。
CREATE
TABLE
IF
NOT
EXISTS cpu (
hostname
STRING
NULL,
region
STRING
NULL,
datacenter
STRING
NULL,
rack
STRING
NULL,
os
STRING
NULL,
arch
STRING
NULL,
team
STRING
NULL,
service
STRING
NULL,
service_version
STRING
NULL,
service_environment
STRING
NULL,
usage_user
BIGINT
NULL,
usage_system
BIGINT
NULL,
usage_idle
BIGINT
NULL,
usage_nice
BIGINT
NULL,
usage_iowait
BIGINT
NULL,
usage_irq
BIGINT
NULL,
usage_softirq
BIGINT
NULL,
usage_steal
BIGINT
NULL,
usage_guest
BIGINT
NULL,
usage_guest_nice
BIGINT
NULL,
ts
TIMESTAMP(
9)
NOT
NULL,
TIME
INDEX (ts),
PRIMARY
KEY (hostname, region, datacenter, rack, os, arch, team, service, service_version, service_environment)
)
with (append_mode=
'true');
CREATE
TABLE
IF
NOT
EXISTS cpu (
hostname
VARCHAR
NULL,
region
VARCHAR
NULL,
datacenter
VARCHAR
NULL,
rack
VARCHAR
NULL,
os
VARCHAR
NULL,
arch
VARCHAR
NULL,
team
VARCHAR
NULL,
service
VARCHAR
NULL,
service_version
VARCHAR
NULL,
service_environment
VARCHAR
NULL,
usage_user
BIGINT
NULL,
usage_system
BIGINT
NULL,
usage_idle
BIGINT
NULL,
usage_nice
BIGINT
NULL,
usage_iowait
BIGINT
NULL,
usage_irq
BIGINT
NULL,
usage_softirq
BIGINT
NULL,
usage_steal
BIGINT
NULL,
usage_guest
BIGINT
NULL,
usage_guest_nice
BIGINT
NULL,
ts
TIMESTAMP
NOT
NULL,
PRIMARY
KEY (hostname, ts)
);
FIVE_MINUTE_1E
SELECT *
FROM cpu
WHERE hostname=
'host_1701'
AND ts>=
'2016-01-01T00:00:00Z'
AND ts<
'2016-01-01T00:05:00';
COUNT
SELECT
count(*)
FROM cpu;
CPU_MAX_ALL_1
-- GreptimeDB
SELECT
max(usage_user),
max(usage_system),
max(usage_idle),
max(usage_nice),
max(usage_iowait),
max(usage_irq),
max(usage_softirq),
max(usage_steal),
max(usage_guest),
max(usage_guest_nice),
date_trunc(
'hour', ts)
FROM
cpu
WHERE
hostname =
'host_1435'
AND
ts >=
'2016-01-01T00:00:00Z'
AND
ts <
'2016-01-01T08:00:00Z'
GROUP
BY
date_trunc(
'hour', ts);
-- SQLite
SELECT
max(usage_user),
max(usage_system),
max(usage_idle),
max(usage_nice),
max(usage_iowait),
max(usage_irq),
max(usage_softirq),
max(usage_steal),
max(usage_guest),
max(usage_guest_nice),
strftime(
'%Y-%m-%dT%H:00:00', ts)
FROM
cpu
WHERE
hostname =
'host_1435'
AND
ts >=
'2016-01-01T00:00:00Z'
AND
ts <
'2016-01-01T08:00:00Z'
GROUP
BY
strftime(
'%Y-%m-%dT%H:00:00', ts);
CPU_MAX_ALL_8
SELECT
max(usage_user),
max(usage_system),
max(usage_idle),
max(usage_nice),
max(usage_iowait),
max(usage_irq),
max(usage_softirq),
max(usage_steal),
max(usage_guest),
max(usage_guest_nice),
date_trunc(
'hour', ts)
FROM
cpu
WHERE
(
hostname =
'host_249'
OR
hostname =
'host_1403'
OR
hostname =
'host_1435'
OR
hostname =
'host_3539'
OR
hostname =
'host_3639'
OR
hostname =
'host_3075'
OR
hostname =
'host_815'
OR
hostname =
'host_2121'
)
AND
ts >=
'2016-01-01T00:00:00Z'
AND
ts <
'2016-01-01T08:00:00Z'
GROUP
BY
date_trunc(
'hour', ts)
-- SQLite
SELECT
max(usage_user),
max(usage_system),
max(usage_idle),
max(usage_nice),
max(usage_iowait),
max(usage_irq),
max(usage_softirq),
max(usage_steal),
max(usage_guest),
max(usage_guest_nice),
strftime(
'%Y-%m-%dT%H:00:00', ts)
FROM
cpu
WHERE
(
hostname =
'host_249'
OR
hostname =
'host_1403'
OR
hostname =
'host_1435'
OR
hostname =
'host_3539'
OR
hostname =
'host_3639'
OR
hostname =
'host_3075'
OR
hostname =
'host_815'
OR
hostname =
'host_2121'
)
AND
ts >=
'2016-01-01T00:00:00Z'
AND
ts <
'2016-01-01T08:00:00Z'
GROUP
BY
strftime(
'%Y-%m-%dT%H:00:00', ts);
SINGLE_GROUP_BY_1_1_1
SELECT
max(usage_user),
date_trunc(
'minute', ts)
FROM
cpu
WHERE
(hostname =
'host_3701')
AND
ts >=
'2016-01-01T00:00:00Z'
AND
ts <
'2016-01-01T08:00:00Z'
GROUP
BY
date_trunc(
'minute', ts)
-- SQLite
SELECT
max(usage_user),
strftime(
'%Y-%m-%dT%H:%M:00', ts)
FROM
cpu
WHERE
(hostname =
'host_1701')
AND
ts >=
'2016-01-01T00:00:00Z'
AND
ts <
'2016-01-01T08:00:00Z'
GROUP
BY
strftime(
'%Y-%m-%dT%H:%M:00', ts);
LAST_POINT_ALL
-- GreptimeDB
SELECT
last_value(hostname
order
by ts),
last_value(region
order
by ts),
last_value(datacenter
order
by ts),
last_value(rack
order
by ts),
last_value(os
order
by ts),
last_value(arch
order
by ts),
last_value(team
order
by ts),
last_value(service
order
by ts),
last_value(service_version
order
by ts),
last_value(service_environment
order
by ts),
last_value(usage_user
order
by ts),
last_value(usage_system
order
by ts),
last_value(usage_idle
order
by ts),
last_value(usage_nice
order
by ts),
last_value(usage_iowait
order
by ts),
last_value(usage_irq
order
by ts),
last_value(usage_softirq
order
by ts),
last_value(usage_steal
order
by ts),
last_value(usage_guest
order
by ts),
last_value(usage_guest_nice
order
by ts)
FROM cpu
GROUP
BY hostname;
--SQLite
SELECT
last_value(hostname)
over(
order
by ts),
last_value(region)
over(
order
by ts),
last_value(datacenter)
over(
order
by ts),
last_value(rack)
over(
order
by ts),
last_value(os)
over(
order
by ts),
last_value(arch)
over(
order
by ts),
last_value(team)
over(
order
by ts),
last_value(service)
over(
order
by ts),
last_value(service_version)
over(
order
by ts),
last_value(service_environment)
over(
order
by ts),
last_value(usage_user)
over(
order
by ts),
last_value(usage_system)
over(
order
by ts),
last_value(usage_idle)
over(
order
by ts),
last_value(usage_nice)
over(
order
by ts),
last_value(usage_iowait)
over(
order
by ts),
last_value(usage_irq)
over(
order
by ts),
last_value(usage_softirq)
over(
order
by ts),
last_value(usage_steal)
over(
order
by ts),
last_value(usage_guest)
over(
order
by ts),
last_value(usage_guest_nice)
over(
order
by ts)
FROM cpu
GROUP
BY hostname;
LAST_POINT_ONE
-- GreptimeDB Edge
SELECT
last_value(hostname
order
by ts),
last_value(region
order
by ts),
last_value(datacenter
order
by ts),
last_value(rack
order
by ts),
last_value(os
order
by ts),
last_value(arch
order
by ts),
last_value(team
order
by ts),
last_value(service
order
by ts),
last_value(service_version
order
by ts),
last_value(service_environment
order
by ts),
last_value(usage_user
order
by ts),
last_value(usage_system
order
by ts),
last_value(usage_idle
order
by ts),
last_value(usage_nice
order
by ts),
last_value(usage_iowait
order
by ts),
last_value(usage_irq
order
by ts),
last_value(usage_softirq
order
by ts),
last_value(usage_steal
order
by ts),
last_value(usage_guest
order
by ts),
last_value(usage_guest_nice
order
by ts)
FROM cpu
WHERE hostname=
'host_1701'
-- SQLite
SELECT
last_value(hostname)
over(
order
by ts),
last_value(region)
over(
order
by ts),
last_value(datacenter)
over(
order
by ts),
last_value(rack)
over(
order
by ts),
last_value(os)
over(
order
by ts),
last_value(arch)
over(
order
by ts),
last_value(team)
over(
order
by ts),
last_value(service)
over(
order
by ts),
last_value(service_version)
over(
order
by ts),
last_value(service_environment)
over(
order
by ts),
last_value(usage_user)
over(
order
by ts),
last_value(usage_system)
over(
order
by ts),
last_value(usage_idle)
over(
order
by ts),
last_value(usage_nice)
over(
order
by ts),
last_value(usage_iowait)
over(
order
by ts),
last_value(usage_irq)
over(
order
by ts),
last_value(usage_softirq)
over(
order
by ts),
last_value(usage_steal)
over(
order
by ts),
last_value(usage_guest)
over(
order
by ts),
last_value(usage_guest_nice)
over(
order
by ts)
FROM cpu
WHERE hostname=
'host_1701'
❝关于 Greptime
Greptime 格睿科技专注于为可观测、物联网及车联网等领域提供实时、高效的数据存储和分析服务,帮助客户挖掘数据的深层价值。目前基于云原生的时序数据库 GreptimeDB 已经衍生出多款适合不同用户的解决方案,更多信息或 demo 展示请联系下方小助手(微信号:greptime)。
欢迎对开源感兴趣的朋友们参与贡献和讨论,从带有 good first issue 标签的 issue 开始你的开源之旅吧~期待在开源社群里遇见你!添加小助手微信即可加入“技术交流群”与志同道合的朋友们面对面交流哦~Star us on GitHub Now: https://github.com/GreptimeTeam/greptimedb
官网: https://greptime.cn/
文档: https://docs.greptime.cn/
Twitter: https://twitter.com/Greptime
Slack: https://greptime.com/slack
LinkedIn: https://www.linkedin.com/company/greptime/
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70031880/viewspace-3044872/ ,如需转载,请注明出处,否则将追究法律责任。