AerospikeC client manual --- shared memory

Source: Internet
Author: User
Tags aerospike

AerospikeC client manual --- shared memory
Zookeeper
In shared memory, each client instance runs an additional cluster server thread and periodically polls each server node of the cluster to get the cluster status. In a single process/multi-thread environment, only one client instance is required. This instance is designed to be shared across multiple threads.
In a multi-process/Single-thread environment, multiple client instances are required, which means that Multiple Cluster Server threads round-robin each server node and get the same cluster status. Shared Memory is designed to solve this inefficiency.
When the sharing mode is enabled, the cluster status (including node and Data Partition ing) is stored in a shared memory segment. Then, there is only one cluster server owner process to poll each service node, get the cluster status, and write it into this shared memory segment. Other clients read the cluster status from the shared memory and no longer poll each server node.
Multi-process/Single-thread environments are common methods in language environments such as PHP and Python. The implementation of the Aerospike PHP and Python clients is to obtain the client's ability to share memory by calling the Aerospike C client.
Shared Memory configuration shared memory is configured using the following domain members of as_config:

/** *  Indicates if shared memory should be used for cluster tending.  Shared memory *  is useful when operating in single threaded mode with multiple client processes. *  This model is used by wrapper languages such as PHP and Python.  When enabled,  *  the data partition maps are maintained by only one process and all other processes  *  use these shared memory maps. * *  Shared memory should not be enabled for multi-threaded programs. *  Default: false */bool use_shm;/** *  Shared memory identifier.  This identifier should be the same for all applications *  that use the Aerospike C client.  *  Default: 0xA5000000 */int shm_key;/** *  Shared memory maximum number of server nodes allowed.  This value is used to size *  the fixed shared memory segment.  Leave a cushion between actual server node *  count and shm_max_nodes so new nodes can be added without having to reboot the client. *  Default: 16 */uint32_t shm_max_nodes;/** *  Shared memory maximum number of namespaces allowed.  This value is used to size *  the fixed shared memory segment.  Leave a cushion between actual namespaces *  and shm_max_namespaces so new namespaces can be added without having to reboot the *  client. *  Default: 8 */uint32_t shm_max_namespaces;/** *  Take over shared memory cluster tending if the cluster hasn't been tended by this *  threshold in seconds. *  Default: 30 */uint32_t shm_takeover_threshold_sec;
Enable shared memory The shared memory mode must be enabled before aerospike_connect.
as_config config;as_config_init(&config);as_config_add_host(&config, host, port);config.use_shm = true;config.shm_key = 0xA5000000;config.shm_max_nodes = 16;config.shm_max_namespaces = 8;config.shm_takeover_threshold_sec = 30;aerospike client;as_error err;aerospike_init(&client, &config);as_status status = aerospike_connect(&client, &err);
Operation remarks

If the shared memory segment does not exist, the client will automatically create it.

The first client process occupies the Cluster Server capability by obtaining the Shared Memory Lock ,.

The subsequent client processes read the cluster status from the shared memory segment, but neither the Cluster Server nor the shared memory is written.

Call aerospike_close () before exiting the application (). This method releases the Shared Memory Lock. Another client process automatically acquires the lock and becomes the owner of the new cluster server.

If the application dies before the lock is released, the other client process will still take over the cluster to be server, but there will be a delay (30 seconds by default ). During this delay, the cluster status is still readable, but the Cluster Server (polling the new cluster status) will not start until another client process takes over.

You can use this command to view shared memory segments:

ipcs -m------ Shared Memory Segments --------key shmid owner perms bytes nattch status 0xA5000000 622592 root 666 263224 0

If the shared memory configuration variable needs to be changed (for example, increasing the maximum number of nodes), the new shared memory segment needs to be re-created. There are two ways to upgrade the application.

One upgrade

Disable all applications.

If the shared memory still exists, delete it.

ipcrm -M 0xA5000000

Restart the application.

Rolling upgrade

Set a different shared memory key in the new application.

config.shm_key = 0xA5000001;

The new application instance uses the new shared memory segment (created by the first new application instance ). The old application instance continues to use the old shared memory segment.

Stop old application instances one by one and replace them with new application instances.

When all old application instances are stopped, the old shared memory segments are deleted (if any ).

ipcrm -M 0xA5000000

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.