mindspore.mint.distributed.TCPStore
- class mindspore.mint.distributed.TCPStore(host_name, port, world_size=None, is_master=False, timeout=timedelta(seconds=300), wait_for_workers=True, multi_tenant=False, master_listen_fd=None, use_libuv=True)[source]
A TCP-based distributed key-value store implementation.
Note
The function is implemented by CPU and does not involve any hardware operations related to Ascend.
Currently, all parameters provided by the TCPStore class constructor are not supported except for host_name, port, world_size, is_master, timeout and wait_for_workers, which are reserved parameters and invalid settings.
The current TCPStore function is limited and only supports scenarios where the key is less than 4k and the value is less than 1G. Complex scenarios are to be supported.
- Parameters
host_name (str) – The hostname or IP Address the server store should run on. Currently only supports user input IP addresses.
port (int) – The port on which the server store should listen for incoming requests.
world_size (int, optional) – The total number of store users (number of clients + 1 for the server). Default is
None
, indicates a non-fixed number of store users. This parameter is only valid for the server.is_master (bool, optional) – True when initializing the server store and False for client stores. Default is
False
.timeout (timedelta, optional) – Timeout used by the store during initialization. Default is
timedelta(seconds=300)
.wait_for_workers (bool, optional) – Whether to wait for all the workers to connect with the server store. This is only applicable when world_size is a fixed value. Default is
True
. This parameter is only valid for the server.multi_tenant (bool, invalid, optional) – If
True
, allTCPStore
instances in the current process with the same host/port will use the same underlyingTCPServer
. Default isFalse
.master_listen_fd (int, invalid, optional) – If specified, the underlying
TCPServer
will listen on this file descriptor, which must be a socket already bound toport
. Useful to avoid port assignment races in some scenarios. Default isNone
(meaning the server creates a new socket and attempts to bind it toport
).use_libuv (bool, invalid, optional) – If True, use libuv for
TCPServer
backend. Default isTrue
.
- Returns
TCPStore Object.
- Supported Platforms:
Ascend
Examples
Note
Before running the following examples, you need to configure the communication environment variables.
For Ascend devices, it is recommended to use the msrun startup method without any third-party or configuration file dependencies. Please see the msrun start up for more details.
>>> from mindspore.mint.distributed import TCPStore >>> store = TCPStore("127.0.0.1", 1234)
- add(key, amount)[source]
When the add function is called for the first time with a given key, it creates a counter in the storage corresponding to that key, with the initial value set to amount. Subsequent calls to add with the same key increment the counter by amount.
- Parameters
- Returns
int, value of counter with key.
- Raises
TypeError – If key is not string.
TypeError – If amount is not int.
RuntimeError – If the add and set pass the same key and the value passed by set cannot be correctly converted to a numerical value, calling add will result in an error.
- Supported Platforms:
Ascend
Examples
Note
Before running the following examples, you need to configure the communication environment variables.
For Ascend devices, it is recommended to use the msrun startup method without any third-party or configuration file dependencies. Please see the msrun start up for more details.
>>> from mindspore.mint.distributed import TCPStore >>> store = TCPStore("127.0.0.1", 1234) >>> store.add("first_key", 1)
- delete_key(key)[source]
Deletes the key-value pair associated with key from the store.
- Parameters
key (str) – The key to be deleted from the store.
- Returns
bool,
True
if key was deleted, otherwiseFalse
.- Raises
TypeError – If key is not string.
- Supported Platforms:
Ascend
Examples
Note
Before running the following examples, you need to configure the communication environment variables.
For Ascend devices, it is recommended to use the msrun startup method without any third-party or configuration file dependencies. Please see the msrun start up for more details.
>>> from mindspore.mint.distributed import TCPStore >>> store = TCPStore("127.0.0.1", 1234) >>> store.set("first_key", "first_value") >>> # This should return true >>> store.delete_key("first_key")
- get(key)[source]
Retrieves the value associated with the given key in the store. If the key does not exist in the storage, this function will wait for the timeout set by the class initialization and then throw an exception.
- Parameters
key (str) – The function will return the value associated with this key.
- Returns
bytes, Value associated with key if key is in the store.
- Raises
TypeError – If key is not string.
RuntimeError – If get runs out of time.
- Supported Platforms:
Ascend
Examples
Note
Before running the following examples, you need to configure the communication environment variables.
For Ascend devices, it is recommended to use the msrun startup method without any third-party or configuration file dependencies. Please see the msrun start up for more details.
>>> from mindspore.mint.distributed import TCPStore >>> store = TCPStore("127.0.0.1", 1234) >>> store.set("first_key", "first_value") >>> data = store.get("first_key") >>> print(data)
- set(key, value)[source]
Inserts the key-value pair into the store based on the supplied key and value. If key already exists in the store, it will overwrite the old value with the new supplied value.
- Parameters
- Raises
- Supported Platforms:
Ascend
Examples
Note
Before running the following examples, you need to configure the communication environment variables.
For Ascend devices, it is recommended to use the msrun startup method without any third-party or configuration file dependencies. Please see the msrun start up for more details.
>>> from mindspore.mint.distributed import TCPStore >>> store = TCPStore("127.0.0.1", 1234) >>> store.set("first_key", "first_value")