Class: CommandQueuePolicy

CommandQueuePolicy

Policy governing the use of the global command queue.

Which commands are affected by the command queue?

Not all client commands use the command queue. Only single-key commands (e.g. Put, Get, etc.), the BatchRead command, and Query#foreach, Scan#foreach commands use the command queue (if enabled).

Commands that are based on the Aerospike info protocol (Index Create/Remove, UDF Register/Remove, Truncate, Info), the legacy Batch Get/Select/Exists commands as well as all other Query and Scan commands do not use the command queue and will always be executed immediately.


new CommandQueuePolicy( [props])

Initializes a new CommandQueuePolicy from the provided policy values.

Parameters:
Name Type Argument Description
props Object <optional>

Policy values

Properties
Name Type Argument Description
maxCommandsInProcess number <optional>

Maximum number of async commands that can be processed at any point in time.

maxCommandsInQueue number <optional>

Maximum number of commands that can be queued for later execution.

queueInitialCapacity number <optional>

Initial capacity of the command queue.

Source:
See:
Example
const Aerospike = require('aerospike')

const policy = {
  maxCommandsInProcess: 50,
  maxCommandsInQueue: 150
}
Aerospike.setupGlobalCommandQueue(policy)

Aerospike.connect()
  .then(client => {
    let commands = []
    for (var i = 0; i < 100; i++) {
      let cmd = client.put(new Aerospike.Key('test', 'test', i), {i: i})
      commands.push(cmd)
    }

    // First 50 commands will be executed immediately,
    // remaining commands will be queued and executed once the client frees up.
    Promise.all(commands)
      .then(() => console.info('All commands executed successfully'))
      .catch(error => console.error('Error:', error))
      .then(() => client.close())
  })

Members


maxCommandsInProcess :Number

Maximum number of commands that can be processed at any point in time. Each executing command requires a socket connection. Consuming too many sockets can negatively affect application reliability and performance. If you do not limit command count in your application, this setting should be used to enforce a limit internally in the client.

If this limit is reached, the next command will be placed on the client's command queue for later execution. If this limit is zero, all commands will be executed immediately and the command queue will not be used. (Note: Config#maxConnsPerNode may still limit number of connections per cluster node.)

If defined, a reasonable value is 40. The optimal value will depend on the CPU speed and network bandwidth.

Type:
  • Number
Default Value:
  • 0 (execute all commands immediately)
Source:

maxCommandsInQueue :Number

Maximum number of commands that can be stored in the global command queue for later execution. Queued commands consume memory, but they do not consume sockets. This limit should be defined when it's possible that the application executes so many commands that memory could be exhausted.

If this limit is reached, the next command will be rejected with error code ERR_ASYNC_QUEUE_FULL. If this limit is zero, all commands will be accepted into the delay queue.

The optimal value will depend on the application's magnitude of command bursts and the amount of memory available to store commands.

Type:
  • Number
Default Value:
  • 0 (no command queue limit)
Source:

queueInitialCapacity :Number

Initial capacity of the command queue. The command queue can resize beyond this initial capacity.

Type:
  • Number
Default Value:
  • 256 (if command queue is used)
Source: