-
Notifications
You must be signed in to change notification settings - Fork 277
DEV: add query performance tuning page #1052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
eb4b4a3
DEV: add query performance tuning page
dwdougherty ed03db9
Apply review comments.
dwdougherty f8db4df
Apply review comments.
dwdougherty 2e85245
Merge branch 'DOC-4716' of github.com:redis/docs into DOC-4716
dwdougherty 7e55c77
Apply more review comments.
dwdougherty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
content/develop/interact/search-and-query/best-practices/_index.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| categories: | ||
| - docs | ||
| - develop | ||
| - stack | ||
| - oss | ||
| description: Redis Query Engine best practices | ||
| linkTitle: Best practices | ||
| title: Best practices | ||
| weight: 2 | ||
| --- | ||
119 changes: 119 additions & 0 deletions
119
...velop/interact/search-and-query/best-practices/scalable-query-best-practices.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| --- | ||
| Title: Best practices for Redis Query Engine performance | ||
| alwaysopen: false | ||
| categories: | ||
| - docs | ||
| - develop | ||
| - stack | ||
| - oss | ||
| - kubernetes | ||
| - clients | ||
| linkTitle: RQE performance | ||
| weight: 1 | ||
| --- | ||
|
|
||
| {{< note >}} | ||
| If you're using Redis Software or Redis Cloud, see the [best practices for scalable Redis Query Engine]({{< relref "/operate/oss_and_stack/stack-with-enterprise/search/scalable-query-best-practices" >}}) page. | ||
| {{< /note >}} | ||
|
|
||
| ## Checklist | ||
| Below are basic steps to ensure good performance of Redis Query Engine. | ||
dwdougherty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| * Create a Redis data model with your query patterns in mind. | ||
| * Ensure the Redis architecture has been sized for the expected load using the [sizing calculator](https://redis.io/redisearch-sizing-calculator/). | ||
| * Provision Redis nodes with sufficient resources (RAM, CPU, network) to support the expected maximum load. | ||
| * Review [`FT.INFO`]({{< baseurl >}}/commands/ft.info) and [`FT.PROFILE`]({{< baseurl >}}/commands/ft.profile) outputs for anomalies and/or errors. | ||
| * Conduct load testing in a test environment with real-world queries and a load generated by either [memtier_benchmark](https://github.com/redislabs/memtier_benchmark) or a custom load application. | ||
|
|
||
| ## Indexing considerations | ||
|
|
||
| ### General | ||
| - Favor [`TAG`]({{< relref "/develop/interact/search-and-query/basic-constructs/field-and-type-options#tag-fields" >}}) over [`NUMERIC`]({{< relref "/develop/interact/search-and-query/basic-constructs/field-and-type-options#numeric-fields" >}}) for use cases that only require matching. | ||
| - Favor [`TAG`]({{< relref "/develop/interact/search-and-query/basic-constructs/field-and-type-options#tag-fields" >}}) over [`TEXT`]({{< relref "/develop/interact/search-and-query/basic-constructs/field-and-type-options#text-fields" >}}) for use cases that don’t require full-text capabilities (pure match). | ||
|
|
||
| ### Non-threaded search | ||
| - Put only those fields used in your queries in the index. | ||
| - Only make fields [`SORTABLE`]({{< relref "/develop/interact/search-and-query/advanced-concepts/sorting" >}}) if they are used in [`SORTBY`]({{< relref "/develop/interact/search-and-query/advanced-concepts/sorting#specifying-sortby" >}}) | ||
| queries. | ||
| - Use [`DIALECT 4`]({{< relref "/develop/interact/search-and-query/advanced-concepts/dialects#dialect-4" >}}). | ||
|
|
||
| ### Threaded (query performance factor or QPF) search | ||
| - Put both query fields and any projected fields (`RETURN` or `LOAD`) in the index. | ||
| - Set all fields to `SORTABLE`. | ||
| - Set TAG fields to [UNF]({{< relref "/develop/interact/search-and-query/advanced-concepts/sorting#normalization-unf-option" >}}). | ||
| - Optional: Set `TEXT` fields to `NOSTEM` if the use case will support it. | ||
| - Use [`DIALECT 4`]({{< relref "/develop/interact/search-and-query/advanced-concepts/dialects#dialect-4" >}}). | ||
|
|
||
| ## Query optimization | ||
|
|
||
| - Avoid returning large result sets. Use `CURSOR` or `LIMIT`. | ||
| - Avoid wildcard searches. | ||
| - Avoid projecting all fields (e.g., `LOAD *`). Project only those fields that are part of the index schema. | ||
| - If queries are long-running, enable threading (query performance factor) to reduce contention for the main Redis thread. | ||
|
|
||
| ## Validate performance (`FT.PROFILE`) | ||
|
|
||
| You can analyze [`FT.PROFILE`]({{< baseurl >}}/commands/ft.profile) output to gain insights about query execution. | ||
| The following informational items are available for analysis: | ||
|
|
||
| - Total execution time | ||
| - Execution time per shard | ||
| - Coordination time (for multi-sharded environments) | ||
| - Breakdown of the query into fundamental components, such as `UNION` and `INTERSECT` | ||
| - Warnings, such as `TIMEOUT` | ||
|
|
||
| ## Anti-patterns | ||
|
|
||
| The following items are anti-patterns for RQE: | ||
|
|
||
| - Large documents | ||
| - Deeply-nested fields | ||
| - Large result sets | ||
| - Wildcarding | ||
| - Large projections | ||
|
|
||
| The following examples depict an anti-pattern index schema and query, followed by a corrected index schema and query, which allows for scalability with the Redis Query Engine. | ||
|
|
||
| ### Anti-pattern index schema | ||
|
|
||
| The following index schema is not optimized for vertical scaling: | ||
|
|
||
| ```sh | ||
| FT.CREATE jsonidx:profiles ON JSON PREFIX 1 profiles: | ||
| SCHEMA $.tags.* as t NUMERIC SORTABLE | ||
| $.firstName as name TEXT | ||
| $.location as loc GEO | ||
| ``` | ||
|
|
||
| ### Anti-pattern query | ||
|
|
||
| The following query is not optimized for vertical scaling: | ||
|
|
||
| ```sh | ||
| FT.AGGREGATE jsonidx:profiles '@t:[1299 1299]' LOAD * LIMIT 0 10 | ||
| ``` | ||
|
|
||
| ### Improved index schema | ||
|
|
||
| Here's an improved index schema that follows best practices for vertical scaling: | ||
|
|
||
| ```sh | ||
| FT.CREATE jsonidx:profiles ON JSON PREFIX 1 profiles: | ||
| SCHEMA $.tags.* as t NUMERIC SORTABLE | ||
| $.firstName as name TEXT NOSTEM SORTABLE | ||
| $.lastName as lastname TEXT NOSTEM SORTABLE | ||
| $.location as loc GEO SORTABLE | ||
| $.id as id TAG SORTABLE UNF | ||
| $.ver as ver TAG SORTABLE UNF | ||
| ``` | ||
|
|
||
| ### Improved query | ||
|
|
||
| Here's an improved query that follows best practices for vertical scaling: | ||
|
|
||
| ```sh | ||
| FT.AGGREGATE jsonidx:profiles '@t:[1299 1299]' | ||
| LOAD 6 id t nam" lastname loc ver | ||
| LIMIT 0 10 | ||
| DIALECT 3 | ||
| ``` | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.