【问题标题】:Ran out of memory searching text in ClickHouse在 ClickHouse 中搜索文本时内存不足
【发布时间】:2019-12-09 04:09:23
【问题描述】:

我正在调查 ClickHouse 是否适合 OLAP 用途。为此,我使用 ClickHouse 的 sintax 复制了我在 PostgreSQL 上运行的一些查询。

我运行的所有查询都比 Postgres 快很多,但是执行文本搜索的查询内存不足。下面是错误代码和堆栈跟踪。

clickhouse_driver.errors.ServerException:代码:241。DB::Exception: 超出内存限制(用于查询):将使用 9.31 GiB(尝试 分配 524288 字节的块),最大值:9.31 GiB。

查询的脚本是:

SELECT COUNT(*)
FROM ObserverNodeOccurrence as occ 
LEFT JOIN
    ObserverNodeOccurrence_NodeElements as occ_ne
    ON occ._id = occ_ne.occurrenceId
WHERE
    occ_ne.snippet LIKE '<img>'

上面的查询计算列 snippet 中包含 HTML 图像 (&lt;img&gt;) 的条目数。此列包含 HTML sn-ps,因此搜索文本变得非常昂贵。近期/中期目标是解析此列并将其转换为一组其他列(例如contains_imgcontains_script 等)。但是,就目前而言,我希望能够运行这样的查询不会耗尽内存

我的问题是:

  • 如何在不耗尽内存的情况下成功地在此类列上执行文本搜索查询?
    • 有没有办法强制查询规划器在内存不足时立即使用磁盘?
    • 我正在使用MergeTree 引擎。是否有其他引擎能够在内存和磁盘之间分担负载?

完整的堆栈跟踪:

clickhouse_driver.errors.ServerException: Code: 241.
DB::Exception: Memory limit (for query) exceeded: would use 9.31 GiB (attempt to allocate chunk of 524288 bytes), maximum: 9.31 GiB. Stack trace:

0. /usr/bin/clickhouse-server(StackTrace::StackTrace()+0x22) [0x781c272]
1. /usr/bin/clickhouse-server(MemoryTracker::alloc(long)+0x8ba) [0x71bbb4a]
2. /usr/bin/clickhouse-server(MemoryTracker::alloc(long)+0xc5) [0x71bb355]
3. /usr/bin/clickhouse-server() [0x67aeb4e]
4. /usr/bin/clickhouse-server() [0x67af010]
5. /usr/bin/clickhouse-server() [0x67e5af4]
6. /usr/bin/clickhouse-server(void DB::Join::joinBlockImpl<(DB::ASTTableJoin::Kind)1, (DB::ASTTableJoin::Strictness)2, DB::Join::MapsTemplate<DB::JoinStuff::WithFlags<DB::RowRefList, false> > >(DB::Block&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, DB::NamesAndTypesList const&, DB::Block const&, DB::Join::MapsTemplate<DB::JoinStuff::WithFlags<DB::RowRefList, false> > const&) const+0xe1c) [0x68020dc]
7. /usr/bin/clickhouse-server(DB::Join::joinBlock(DB::Block&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, DB::NamesAndTypesList const&) const+0x1a5) [0x67bc415]
8. /usr/bin/clickhouse-server(DB::ExpressionAction::execute(DB::Block&, bool) const+0xa5d) [0x6d961dd]
9. /usr/bin/clickhouse-server(DB::ExpressionActions::execute(DB::Block&, bool) const+0x45) [0x6d97545]
10. /usr/bin/clickhouse-server(DB::ExpressionBlockInputStream::readImpl()+0x48) [0x6c52888]
11. /usr/bin/clickhouse-server(DB::IBlockInputStream::read()+0x188) [0x6635628]
12. /usr/bin/clickhouse-server(DB::FilterBlockInputStream::readImpl()+0xd9) [0x6c538b9]
13. /usr/bin/clickhouse-server(DB::IBlockInputStream::read()+0x188) [0x6635628]
14. /usr/bin/clickhouse-server(DB::ExpressionBlockInputStream::readImpl()+0x2d) [0x6c5286d]
15. /usr/bin/clickhouse-server(DB::IBlockInputStream::read()+0x188) [0x6635628]
16. /usr/bin/clickhouse-server(DB::ParallelInputsProcessor<DB::ParallelAggregatingBlockInputStream::Handler>::loop(unsigned long)+0x139) [0x6c7f409]
17. /usr/bin/clickhouse-server(DB::ParallelInputsProcessor<DB::ParallelAggregatingBlockInputStream::Handler>::thread(std::shared_ptr<DB::ThreadGroupStatus>, unsigned long)+0x209) [0x6c7fc79]
18. /usr/bin/clickhouse-server(ThreadFromGlobalPool::ThreadFromGlobalPool<void (DB::ParallelInputsProcessor<DB::ParallelAggregatingBlockInputStream::Handler>::*)(std::shared_ptr<DB::ThreadGroupStatus>, unsigned long), DB::ParallelInputsProcessor<DB::ParallelAggregatingBlockInputStream::Handler>*, std::shared_ptr<DB::ThreadGroupStatus>, unsigned long&>(void (DB::ParallelInputsProcessor<DB::ParallelAggregatingBlockInputStream::Handler>::*&&)(std::shared_ptr<DB::ThreadGroupStatus>, unsigned long), DB::ParallelInputsProcessor<DB::ParallelAggregatingBlockInputStream::Handler>*&&, std::shared_ptr<DB::ThreadGroupStatus>&&, unsigned long&)::{lambda()#1}::operator()() const+0x7f) [0x6c801cf]
19. /usr/bin/clickhouse-server(ThreadPoolImpl<std::thread>::worker(std::_List_iterator<std::thread>)+0x1af) [0x71c778f]
20. /usr/bin/clickhouse-server() [0xb2ac5bf]
21. /lib/x86_64-linux-gnu/libpthread.so.0(+0x76db) [0x7fc5b50826db]
22. /lib/x86_64-linux-gnu/libc.so.6(clone+0x3f) [0x7fc5b480988f]

【问题讨论】:

  • 我认为唯一的方法是增加内存限制。但在你的情况下,你可以重写query,它会在没有out of memory的情况下工作。

标签: full-text-search sqlperformance clickhouse


【解决方案1】:

在终端运行 Clickhouse-Client

set max_bytes_before_external_group_by=20000000000;  --20 GB for external group by
set max_memory_usage=40000000000; --40GB for memory limit

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-21
    • 1970-01-01
    • 1970-01-01
    • 2023-01-31
    • 2017-06-22
    • 2023-04-07
    • 2019-06-26
    • 2011-09-18
    相关资源
    最近更新 更多