首页 > 技术文章 > Clickhosue & ck & ch DB::Exception: Memory limit (total) exceeded

worldline 2021-03-25 14:23 原文

1.异常信息

<Error> ConfigReloader: void DB::ConfigReloader::run(): Code: 241, e.displayText() = DB::Exception: Memory limi  t (total) exceeded: would use 19.24 GiB (attempt to allocate chunk of 5242880 bytes), maximum: 18.63 GiB, Stack trace (when copying this message, alway  s include the lines below):
0.  Poco::Exception::Exception(std::1::basic_string<char, std::1::char_traits<char>, std::__1::allocator<char> > const&, int) @ 0x18e02790 in /usr/b  in/clickhouse
1.  DB::Exception::Exception(std::1::basic_string<char, std::1::char_traits<char>, std::__1::allocator<char> > const&, int) @ 0xe72fdad in /usr/bin/  clickhouse
2.  ? @ 0xe71dee0 in /usr/bin/clickhouse
3.  MemoryTracker::alloc(long) @ 0xe71c798 in /usr/bin/clickhouse
4.  operator new[](unsigned%20long) @ 0xe71af6c in /usr/bin/clickhouse
5.  Poco::XML::NamePool::NamePool(unsigned long) @ 0x18d84fca in /usr/bin/clickhouse

2.解决

1.config.xml
	修改每个节点上的config.xml配置文件里的服务器使用最大RAM量
		<max_server_memory_usage>xxx</max_server_memory_usage>
2.users.xml
	修改每个节点上的users.xml配置文件里的,用于在单个服务器上运行查询的最大RAM量
		<max_memory_usage>xxx</max_memory_usage>

3.扩展

1.max_memory_usage
	含义:用于在单个服务器上运行查询的最大RAM量
	默认值: 10G
	内存的使用也受限于这两个参数
		1)max_memory_usage_for_user
			用于在单个服务器上运行用户查询的最大RAM量
			默认值定义在 Settings.h (https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/Settings.h)
			默认值是0, max_memory_usage_for_user = 0 表示不受限
		2)max_server_memory_usage
        	详见 2
        	
2.max_server_memory_usage
	含义:限制ClickHouse服务器节点的总RAM使用量
	默认值: 0 默认情况下的计算公式如下:
		max_server_memory_usage = memory_amount(内存总量) * max_server_memory_usage_to_ram_ratio(占比分数值)
		
		
3.max_server_memory_usage_to_ram_ratio
	含义:定义可用于Clickhouse服务器的总物理RAM量的一部分。如果想要服务器利用更多资源(限制ck应用在内存占用),则会将内存减少到适当的数量
	默认值:0 表示Clickhouse服务器可以使用所有可用的RAM
	官方建议:
		在具有低RAM和交换容量的主机上,可能需要将max_server_memory_usage_to_ram_ratio设置为大于1
	

推荐阅读