简体   繁体   English

ClickHouse 中的多租户

[英]Multi Tenancy in ClickHouse

A lot of people don't want to use ClickHouse just to do analytics for their company or project.很多人不想使用 ClickHouse 来为他们的公司或项目进行分析。 They want to use it as the backbone for SaaS data/analytics projects.他们希望将其用作 SaaS 数据/分析项目的支柱。 Which most of the time would require supporting semi-structured json data, which could result in creating a lot of columns for each user you have.大多数情况下需要支持半结构化 json 数据,这可能会导致为您拥有的每个用户创建大量列。

Now, some experinced ClickHouse users say less tables means more performance.现在,一些有经验的 ClickHouse 用户更少的表意味着更高的性能。 So having a seperate table for each user is not an option.因此,为每个用户提供单独的表不是一种选择。

Also, having the data of too many users into the same database will result in a very large number of columns, which some experiments say it could make CH unresponsive.此外,将太多用户的数据放入同一个数据库会导致列数非常多,一些实验表明这可能会使 CH 无响应。

So what about something like 20 users per database having each user limited to 50 columns.那么每个数据库有 20 个用户,每个用户限制为 50 列呢? But what if you got thousands of users?但是如果你有成千上万的用户呢? Should you create thousands of databases?您应该创建数千个数据库吗?

What is the best solution possible to this problem?这个问题的最佳解决方案是什么?

Note: In our case, data isolation is not an issue, we are solving it on the application level.注意:在我们的案例中,数据隔离不是问题,我们正在应用程序级别解决它。

There is no difference between 1000 tables in a single database and 1000 databases with a single table.单库1000表和单表1000库没有区别。

There is ALMOST no difference between 1000 tables and a table with *1000 partitions partition by (tenant_id, .some_expression_from_datetime.) 1000 个表和具有 *1000 个分区的表之间几乎没有区别partition by (tenant_id, .some_expression_from_datetime.)

The problem is in overhead from MergeTree and ReplicatedMergeTree Engines.问题在于 MergeTree 和 ReplicatedMergeTree 引擎的开销。 And is in number of files you need to create / read (data locality problem, not related to files, will be the same without a filesystem).并且是您需要创建/读取的文件数量(与文件无关的数据局部性问题,在没有文件系统的情况下将是相同的)。

If you have 1000 tenants, the only way is to use order by (tenant_id,..) + restrictions using row policies or on application level.如果您有 1000 个租户,唯一的方法是使用order by (tenant_id,..) + 使用行策略或应用程序级别的限制。

I have an experience with customers who have 700 Replicated tables -- it's constant straggle with the replication, need to adjust background pools, the problem with ZK (huge DB size, enormous network traffic between CH and ZK).我有一个拥有 700 个复制表的客户的经验——复制经常出现问题,需要调整后台池,ZK 的问题(巨大的数据库大小,CH 和 ZK 之间的巨大网络流量)。 Clickhouse starts for 4 hours because it needs to read metadata from all 1000000 parts. Clickhouse 启动 4 小时,因为它需要从所有 1000000 个部件中读取元数据。 Partition pruning works slower because it iterates through all parts during query analysis for every query.分区修剪工作较慢,因为它在每个查询的查询分析期间迭代所有部分。

The source of the issue is the original design, they had about 3 tables in metrika i guess.问题的根源是原始设计,我猜他们在 metrika 中有大约 3 张桌子。

Check this for example https://github.com/ClickHouse/ClickHouse/issues/31919检查这个例如https://github.com/ClickHouse/ClickHouse/issues/31919

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM