ToB企服应用市场:ToB评测及商务社交产业平台

标题: 大数据 - ClickHouse [打印本页]

作者: 耶耶耶耶耶    时间: 2023-1-5 16:30
标题: 大数据 - ClickHouse
https://clickhouse.com/
概念

ClickHouse 是俄罗斯的 Yandex 于 2016 年开源的列式存储数据库(DBMS),使用 C++语言编写,主要用于在线分析处理查询(OLAP),能够使用 SQL 查询实时生成分析数据报告。
OLAP:一次写入,多次读取
ClickHouse凭借着其出色的分析查询性能,尤其是在日志处理上的优势,非常有效的解决了关系型数据库在海量数据场景下的分析查询短板问题
ClickHouse 的特点

IdNameAge1张三182李四223王五34➢ 采用行式存储时,数据在磁盘上的组织结构为:
1张三182李四223王五34
好处是想查某个人所有的属性时,可以通过一次磁盘查找加顺序读取就可以。但是当想查所有人的年龄时,需要不停的查找,或者全表扫描才行,遍历的很多数据都是不需要的。➢ 采用列式存储时,数据在磁盘上的组织结构为:
123张三李四王五182234
这时想查所有人的年龄只需把年龄那一列拿出来就可以了➢ **列式储存的好处:**- 方便聚合,对于列的聚合,计数,求和等统计操作原因优于行式存储。- 由于某一列的数据类型都是相同的,针对于数据存储更容易进行数据压缩,每一列选择更优的数据压缩算法,大大提高了数据的压缩比重。- 由于数据压缩比更好,一方面节省了磁盘空间,另一方面对于 cache 也有了更大的发挥空间。DBMS 的功能
几乎覆盖了标准 SQL 的大部分语法,包括 DDL 和 DML,以及配套的各种函数,用户管理及权限管理,数据的备份与恢复。
多样化引擎
ClickHouse 和 MySQL 类似,把表级的存储引擎插件化,根据表的不同需求可以设定
不同的存储引擎。目前包括合并树、日志、接口和其他四大类 20 多种引擎。
高吞吐写入能力
ClickHouse 采用类 LSM Tree 的结构,数据写入后定期在后台 Compaction。通过类 LSM tree 的结构,ClickHouse 在数据导入时全部是顺序 append 写,写入后数据段不可更改,在后台 compaction 时也是多个段 merge sort 后顺序写回磁盘。顺序写的特性,充分利用了磁盘的吞吐能力,即便在 HDD 上也有着优异的写入性能。
官方公开 benchmark 测试显示能够达到 50MB-200MB/s 的写入吞吐能力,按照每行 100Byte 估算,大约相当于 50W-200W 条/s 的写入速度。
数据分区与线程级并行
ClickHouse 将数据划分为多个 partition,每个 partition 再进一步划分为多个 index granularity(索引粒度),然后通过多个 CPU 核心分别处理其中的一部分来实现并行数据处理。在这种设计下,单条 Query 就能利用整机所有 CPU。极致的并行处理能力,极大的降低了查询延时。
所以,ClickHouse 即使对于大量数据的查询也能够化整为零平行处理。但是有一个弊端就是对于单条查询使用多 cpu,就不利于同时并发多条查询。所以对于高 QPS(Queries Per Second 每秒查询率) 的查询业务,ClickHouse 并不是强项
性能对比
单表查询

关联查询

结论: ClickHouse 像很多 OLAP 数据库一样,单表查询速度由于关联查询,而且ClickHouse 的两者差距更为明显。
安装

https://clickhouse.com/docs/en/install/
  1. [root@VipSoft clickhouse]# pwd
  2. /opt/clickhouse
  3. # 下载安装程序
  4. [root@VipSoft clickhouse]# curl https://clickhouse.com/ | sh
  5.   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
  6.                                  Dload  Upload   Total   Spent    Left  Speed
  7. 100  2473    0  2473    0     0   1514      0 --:--:--  0:00:01 --:--:--  1515
  8. Will download https://builds.clickhouse.com/master/amd64/clickhouse into clickhouse
  9.   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
  10.                                  Dload  Upload   Total   Spent    Left  Speed
  11. 100  502M  100  502M    0     0  5262k      0  0:01:37  0:01:37 --:--:-- 6022k
  12. Successfully downloaded the ClickHouse binary, you can run it as:
  13.     ./clickhouse
  14. You can also install it:
  15.     sudo ./clickhouse install
  16. # 设置权限
  17. [root@VipSoft clickhouse]# chmod -R 775 ./
  18. [root@VipSoft clickhouse]# ll
  19. total 4447904
  20. -rwxrwxr-x 1 root root 2147479552 Dec 30 13:46 clickhouse
  21. [root@VipSoft clickhouse]# ./clickhouse install
  22. Copying ClickHouse binary to /usr/bin/clickhouse.new
  23. Renaming /usr/bin/clickhouse.new to /usr/bin/clickhouse.
  24. Creating symlink /usr/bin/clickhouse-server to /usr/bin/clickhouse.
  25. Creating symlink /usr/bin/clickhouse-client to /usr/bin/clickhouse.
  26. Creating symlink /usr/bin/clickhouse-local to /usr/bin/clickhouse.
  27. Creating symlink /usr/bin/clickhouse-benchmark to /usr/bin/clickhouse.
  28. Creating symlink /usr/bin/clickhouse-copier to /usr/bin/clickhouse.
  29. Creating symlink /usr/bin/clickhouse-obfuscator to /usr/bin/clickhouse.
  30. Creating symlink /usr/bin/clickhouse-git-import to /usr/bin/clickhouse.
  31. Creating symlink /usr/bin/clickhouse-compressor to /usr/bin/clickhouse.
  32. Creating symlink /usr/bin/clickhouse-format to /usr/bin/clickhouse.
  33. Creating symlink /usr/bin/clickhouse-extract-from-config to /usr/bin/clickhouse.
  34. Creating symlink /usr/bin/clickhouse-keeper to /usr/bin/clickhouse.
  35. Creating symlink /usr/bin/clickhouse-keeper-converter to /usr/bin/clickhouse.
  36. Creating symlink /usr/bin/clickhouse-disks to /usr/bin/clickhouse.
  37. Creating clickhouse group if it does not exist.
  38. groupadd -r clickhouse
  39. Creating clickhouse user if it does not exist.
  40. useradd -r --shell /bin/false --home-dir /nonexistent -g clickhouse clickhouse
  41. Will set ulimits for clickhouse user in /etc/security/limits.d/clickhouse.conf.
  42. Creating config directory /etc/clickhouse-server.
  43. Creating config directory /etc/clickhouse-server/config.d that is used for tweaks of main server configuration.
  44. Creating config directory /etc/clickhouse-server/users.d that is used for tweaks of users configuration.
  45. Data path configuration override is saved to file /etc/clickhouse-server/config.d/data-paths.xml.
  46. Log path configuration override is saved to file /etc/clickhouse-server/config.d/logger.xml.
  47. User directory path configuration override is saved to file /etc/clickhouse-server/config.d/user-directories.xml.
  48. OpenSSL path configuration override is saved to file /etc/clickhouse-server/config.d/openssl.xml.
  49. Creating log directory /var/log/clickhouse-server.
  50. Creating data directory /var/lib/clickhouse.
  51. Creating pid directory /var/run/clickhouse-server.
  52. chown -R clickhouse:clickhouse '/var/log/clickhouse-server'
  53. chown -R clickhouse:clickhouse '/var/run/clickhouse-server'
  54. chown  clickhouse:clickhouse '/var/lib/clickhouse'
  55. Enter password for default user: 【输入密码】# 输入密码
  56. Password for default user is saved in file /etc/clickhouse-server/users.d/default-password.xml.
  57. Setting capabilities for clickhouse binary. This is optional.
  58. Cannot set 'net_admin' or 'ipc_lock' or 'sys_nice' or 'net_bind_service' capability for clickhouse binary. This is optional. Taskstats accounting will be disabled. To enable taskstats accounting you may add the required capability later manually.
  59. Allow server to accept connections from the network (default is localhost only), [y/N]: y # 允许外面访问
  60. The choice is saved in file /etc/clickhouse-server/config.d/listen.xml.
  61. chown -R clickhouse:clickhouse '/etc/clickhouse-server'
  62. ClickHouse has been successfully installed.
  63. Start clickhouse-server with:
  64. sudo clickhouse start
  65. Start clickhouse-client with:
  66. clickhouse-client --password
  67. # 启动服务
  68. [root@VipSoft clickhouse]# clickhouse start
  69. chown -R clickhouse: '/var/run/clickhouse-server/'
  70. Will run sudo -u 'clickhouse' /usr/bin/clickhouse-server --config-file /etc/clickhouse-server/config.xml --pid-file /var/run/clickhouse-server/clickhouse-server.pid --daemon
  71. Waiting for server to start
  72. Waiting for server to start
  73. Waiting for server to start
  74. Waiting for server to start
  75. Waiting for server to start
  76. Server started
复制代码
客户端工具

DBeaver、NineData

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4