# optimize

## Description

Recommends best practices and optimizes the cluster for maximum performance.

This command makes or recommends the following best practices:

* By default, if `--memory-percentage` is not specified, sets `maximum_memory` to either 90% of the total RAM available to a leaf or aggregator node, or to the total RAM available to the node minus 10 GB or minus 5 GB multiplied by number of nodes, whichever is greater.
* If `--memory-percentage` is specified, sets `maximum_memory` to that percentage of the total RAM available to a leaf or aggregator node.
* If the `maximum_blob_cache_size_percent` variable is set, checks that the total cache reserved by all leaf nodes does not exceed the disk size. Otherwise, sets `maximum_blob_cache_size_mb` to an optimal value.
* If there are multiple leaf or aggregator nodes on the same host, the memory allocation will be divided evenly among the nodes of the same type.
* If there are leaf and aggregator nodes on the host, 3/4 of the memory will be allocated to the leaf nodes and 1/4 of the memory will be allocated to the aggregator nodes.
* Queries for the NUMA node count on the host. If `numactl` is installed on the host, `optimize` will set up the NUMA binding based on the number of NUMA nodes on the host and the number of leaf nodes created.
* Deploying additional leaf nodes is recommended if the number of leaf nodes is less than what the NUMA configuration recommends.
* If `--bind-to-l3` is specified, and the host has only one NUMA node, `memsqlctl optimize` will set up the CPU binding based on L3 cache indices and the number of leaf nodes created on the host.

## Usage

```
Usage:
  memsqlctl optimize [flags]

Flags:
      --bind-to-l3              Bind leaf nodes to CPUs based on the L3 cache index
      --blob-cache-max-size     Optimize the maximum_blob_cache_size_mb value for each leaf node (default true)
  -h, --help                    Help for optimize
      --memory-percentage INT   The percentage of memory to use for the database on each host
      --no-numa                 Do not change NUMA settings on any nodes

Global Flags:
  -c, --config FILE_PATH                     Path to the memsqctl config file
      --default-install-dir DIRECTORY_PATH   Path to the default install directory
      --insecure-ssl                         Fall back to insecure SSL connections to local nodes if memsqlctl is unable to otherwise establish a connection (ADVANCED)
  -j, --json                                 Print output in JSON format
      --node-metadata-file FILE_PATH         Path to the node metadata file
      --parallelism POSITIVE_INTEGER         Maximum amount of operations to be run in parallel
      --ssl-ca FILE_PATH                     The path to the CA certificate file (in PEM format) to authenticate the database certificate
      --timeout duration                     Maximum time for operation to complete (e.g., 30s, 10m, 1.5h)
      --verbose-json                         Print output in JSON format, include some warnings and user messages
  -v, --verbosity count                      Increase logging verbosity
  -y, --yes                                  Enable non-interactive mode and assume the user would like to move forward with the proposed actions by default
```

## Remarks

* This command is interactive unless you use either `--yes` or `--json` flag to override interactive behavior.
* The `memsqlctl optimize` command is equivalent to the `sdb-admin optimize` command.

## Output

The following example shows how to use `optimize` to increase memory size on a leaf node to align with deployment best practices.

```shell
sudo memsqlctl optimize

```

```output

Warning: The maximum memory per node, 7184 MB, is less than SingleStore's minimum recommendation of 7372 MB per node.
memsqlctl will perform the following actions:
  · On leaf node with MemSQL ID 7DE9330A9F374C580C9857C851CE3A8380DA2FFC on port 3307
    - Set maximum_memory to 7184 MB

Would you like to continue? [y/N]: y
✓ Updated MemSQL config file with setting 'maximum_memory = 7184' for node with MemSQL ID 7DE9330A9F374C580C9857C851CE3A8380DA2FFC
✓ Executed 'SET GLOBAL maximum_memory=7184' command on node with MemSQL ID 7DE9330A9F374C580C9857C851CE3A8380DA2FFC

```

***

Modified at: November 6, 2024

Source: [/db/v9.1/reference/singlestore-tools-reference/memsqlctl-commands/optimize/](https://docs.singlestore.com/db/v9.1/reference/singlestore-tools-reference/memsqlctl-commands/optimize/)

(An index of the documentation is available at /llms.txt)
