`SlowLog` 在 `RedisSearch` 中依赖于什么?

huangapple go评论57阅读模式
英文:

What does `SlowLog` in `RedisSearch` depends on?

问题

我在处理RedisSearch查询,我想了解SlowLog。当我的键超过500k时,即使是下面这个简单的Aggregate查询,所有的查询都被记录为SlowLog

FT.Aggregate roomDailySpecs-idx * GroupBy 1 @RoomId Reduce AVG "1" @Price as avg_price Filter @avg_price>30000

我想知道,为什么这个查询很慢,它是否取决于硬件,比如内存CPU

英文:

I'm working on RedisSearch queries, I wonder about SlowLog.
When my keys are more than 500k , all of my queries log as SlowLog, even the following simple Aggregate query:

FT.Aggregate roomDailySpecs-idx * GroupBy 1 @RoomId Reduce AVG "1" @Price as avg_price Filter @avg_price>30000

I want to know, why that query is slow , Can it depends on Hardwares like Ram or CPU?

答案1

得分: 3

SLOWLOG日志记录了所有查询和命令,其执行时间超过slowlog-log-slower-than毫秒阈值, 默认为10毫秒。您可以在此处详细了解此配置。您可以将阈值设置为较大的值,以仅捕获非常慢的执行。

您包含的查询可能很简单,但它需要扫描您索引中的整个文档表。除此之外,如果您没有将@RoomId@Price字段标记为SORTABLE,还需要为每个文档从Redis键空间加载值。根据文档:

SORTABLE - 数字、标签、文本或地理属性可以具有可选的SORTABLE参数。当用户按照此属性的值对结果进行排序时,结果可以以非常低的延迟可用。请注意,这会增加内存开销,因此请考虑不要在大型文本属性上声明它。您可以在没有SORTABLE选项的情况下对属性进行排序,但延迟不如SORTABLE好。

您可以在此处详细了解SORTABLE字段。

总之,如果您希望不在慢查询日志中看到FT.AGGREGATE命令,可以将阈值设置得更高,或尝试加快查询执行时间,记住通配符查询的任何聚合都需要完全扫描所有文档,因此它与索引大小强相关。

英文:

The SLOWLOG log records all queries and commands that took more than slowlog-log-slower-than ms threshold, which is 10 ms by default. You can read more about this configuration here. You can set the threshold to some larger value to catch only very slow executions.

The query you included might be simple, but it requires to scan the entire document table in your index. In addition to that, if you didn’t mark the @RoomId and @Price fields as SORTABLEs, it also requires to load the values from the redis key space for every document. From the docs:

> SORTABLE - NUMERIC, TAG, TEXT, or GEO attributes can have an optional SORTABLE argument. As the user sorts the results by the value of this attribute, the results are available with very low latency. Note that his adds memory overhead, so consider not declaring it on large text attributes. You can sort an attribute without the SORTABLE option, but the latency is not as good as with SORTABLE.

You can read more about SORTABLE fields here.

In conclusion, if you wish to not see the FT.AGGREGATE commands in your slowlog, you can either make the threshold higher, or try to speed up the query execution time, and remember that any aggregation of a wildcard query requires a complete scan of all the documents, and therefore it will be strongly correlated to the index size.

huangapple
  • 本文由 发表于 2023年5月8日 00:32:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76195081.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定