-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Milvus-doc-bot
authored and
Milvus-doc-bot
committed
Jan 22, 2025
1 parent
df9b6cc
commit 928fac9
Showing
3 changed files
with
44 additions
and
44 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1 +1 @@ | ||
{"codeList":["{\n \"requests\": { \"nodeNum\": 1 },\n \"limits\": { \"nodeNum\": 1 },\n \"transfer_from\": [{ \"resource_group\": \"rg1\" }],\n \"transfer_to\": [{ \"resource_group\": \"rg2\" }]\n}\n","import pymilvus\n\n# A resource group name should be a string of 1 to 255 characters, starting with a letter or an underscore (_) and containing only numbers, letters, and underscores (_).\nname = \"rg\"\nnode_num = 0\n\n# create a resource group that exactly hold no query node.\ntry:\n utility.create_resource_group(name, config=utility.ResourceGroupConfig(\n requests={\"node_num\": node_num},\n limits={\"node_num\": node_num},\n ), using='default')\n print(f\"Succeeded in creating resource group {name}.\")\nexcept Exception:\n print(\"Failed to create the resource group.\")\n","rgs = utility.list_resource_groups(using='default')\nprint(f\"Resource group list: {rgs}\")\n\n# Resource group list: ['__default_resource_group', 'rg']\n","info = utility.describe_resource_group(name, using=\"default\")\nprint(f\"Resource group description: {info}\")\n\n# Resource group description: \n# <name:\"rg\">, // string, rg name\n# <capacity:1>, // int, num_node which has been transfer to this rg\n# <num_available_node:0>, // int, available node_num, some node may shutdown\n# <num_loaded_replica:{}>, // map[string]int, from collection_name to loaded replica of each collecion in this rg\n# <num_outgoing_node:{}>, // map[string]int, from collection_name to outgoging accessed node num by replica loaded in this rg \n# <num_incoming_node:{}>. // map[string]int, from collection_name to incoming accessed node num by replica loaded in other rg\n","source = '__default_resource_group'\ntarget = 'rg'\nexpected_num_nodes_in_default = 0\nexpected_num_nodes_in_rg = 1\n\ntry:\n utility.update_resource_groups({\n source: ResourceGroupConfig(\n requests={\"node_num\": expected_num_nodes_in_default},\n limits={\"node_num\": expected_num_nodes_in_default},\n ),\n target: ResourceGroupConfig(\n requests={\"node_num\": expected_num_nodes_in_rg},\n limits={\"node_num\": expected_num_nodes_in_rg},\n )\n }, using=\"default\")\n print(f\"Succeeded in move 1 node(s) from {source} to {target}.\")\nexcept Exception:\n print(\"Something went wrong while moving nodes.\")\n\n# After a while, succeeded in moving 1 node(s) from __default_resource_group to rg.\n","from pymilvus import Collection\n\ncollection = Collection('demo')\n\n# Milvus loads the collection to the default resource group.\ncollection.load(replica_number=2)\n\n# Or, you can ask Milvus load the collection to the desired resource group.\n# make sure that query nodes num should be greater or equal to replica_number\nresource_groups = ['rg']\ncollection.load(replica_number=2, _resource_groups=resource_groups) \n","collection = Collection(\"Books\")\n\n# Use the load method of a collection to load one of its partition\ncollection.load([\"Novels\"], replica_number=2, _resource_groups=resource_groups)\n\n# Or, you can use the load method of a partition directly\npartition = Partition(collection, \"Novels\")\npartition.load(replica_number=2, _resource_groups=resource_groups)\n","source = '__default_resource_group'\ntarget = 'rg'\ncollection_name = 'c'\nnum_replicas = 1\n\ntry:\n utility.transfer_replica(source, target, collection_name, num_replicas, using=\"default\")\n print(f\"Succeeded in moving {num_node} replica(s) of {collection_name} from {source} to {target}.\")\nexcept Exception:\n print(\"Something went wrong while moving replicas.\")\n\n# Succeeded in moving 1 replica(s) of c from __default_resource_group to rg.\n","try:\n utility.update_resource_groups({\n \"rg\": utility.ResourceGroupConfig(\n requests={\"node_num\": 0},\n limits={\"node_num\": 0},\n ),\n }, using=\"default\")\n utility.drop_resource_group(\"rg\", using=\"default\")\n print(f\"Succeeded in dropping {source}.\")\nexcept Exception:\n print(f\"Something went wrong while dropping {source}.\")\n","from pymilvus import utility\nfrom pymilvus.client.types import ResourceGroupConfig\n\n_PENDING_NODES_RESOURCE_GROUP=\"__pending_nodes\"\n\ndef init_cluster(node_num: int):\n print(f\"Init cluster with {node_num} nodes, all nodes will be put in default resource group\")\n # create a pending resource group, which can used to hold the pending nodes that do not hold any data.\n utility.create_resource_group(name=_PENDING_NODES_RESOURCE_GROUP, config=ResourceGroupConfig(\n requests={\"node_num\": 0}, # this resource group can hold 0 nodes, no data will be load on it.\n limits={\"node_num\": 10000}, # this resource group can hold at most 10000 nodes \n ))\n\n # update default resource group, which can used to hold the nodes that all initial node in it.\n utility.update_resource_groups({\n \"__default_resource_group\": ResourceGroupConfig(\n requests={\"node_num\": node_num},\n limits={\"node_num\": node_num},\n transfer_from=[{\"resource_group\": _PENDING_NODES_RESOURCE_GROUP}], # recover missing node from pending resource group at high priority.\n transfer_to=[{\"resource_group\": _PENDING_NODES_RESOURCE_GROUP}], # recover redundant node to pending resource group at low priority.\n )})\n utility.create_resource_group(name=\"rg1\", config=ResourceGroupConfig(\n requests={\"node_num\": 0},\n limits={\"node_num\": 0},\n transfer_from=[{\"resource_group\": _PENDING_NODES_RESOURCE_GROUP}], \n transfer_to=[{\"resource_group\": _PENDING_NODES_RESOURCE_GROUP}],\n ))\n utility.create_resource_group(name=\"rg2\", config=ResourceGroupConfig(\n requests={\"node_num\": 0},\n limits={\"node_num\": 0},\n transfer_from=[{\"resource_group\": _PENDING_NODES_RESOURCE_GROUP}], \n transfer_to=[{\"resource_group\": _PENDING_NODES_RESOURCE_GROUP}],\n ))\n\ninit_cluster(1)\n","\ndef scale_to(node_num: int):\n # scale the querynode number in Milvus into node_num.\n pass\n","# scale rg1 into 3 nodes, rg2 into 1 nodes\nutility.update_resource_groups({\n \"rg1\": ResourceGroupConfig(\n requests={\"node_num\": 3},\n limits={\"node_num\": 3},\n transfer_from=[{\"resource_group\": _PENDING_NODES_RESOURCE_GROUP}],\n transfer_to=[{\"resource_group\": _PENDING_NODES_RESOURCE_GROUP}],\n ),\n \"rg2\": ResourceGroupConfig(\n requests={\"node_num\": 1},\n limits={\"node_num\": 1},\n transfer_from=[{\"resource_group\": _PENDING_NODES_RESOURCE_GROUP}],\n transfer_to=[{\"resource_group\": _PENDING_NODES_RESOURCE_GROUP}],\n ),\n})\nscale_to(5)\n# rg1 has 3 nodes, rg2 has 1 node, __default_resource_group has 1 node.\n","# scale rg1 from 3 nodes into 2 nodes\nutility.update_resource_groups({\n \"rg1\": ResourceGroupConfig(\n requests={\"node_num\": 2},\n limits={\"node_num\": 2},\n transfer_from=[{\"resource_group\": _PENDING_NODES_RESOURCE_GROUP}],\n transfer_to=[{\"resource_group\": _PENDING_NODES_RESOURCE_GROUP}],\n ),\n})\n\n# rg1 has 2 nodes, rg2 has 1 node, __default_resource_group has 1 node, __pending_nodes has 1 node.\nscale_to(4)\n# scale the node in __pending_nodes\n"],"headingContent":"Manage Resource Groups","anchorList":[{"label":"Manage Resource Groups","href":"Manage-Resource-Groups","type":1,"isActive":false},{"label":"What is a resource group","href":"What-is-a-resource-group","type":2,"isActive":false},{"label":"Concepts of resource group","href":"Concepts-of-resource-group","type":2,"isActive":false},{"label":"Use declarative api to manage resource group","href":"Use-declarative-api-to-manage-resource-group","type":2,"isActive":false},{"label":"A good practice to manage cluster scaling","href":"A-good-practice-to-manage-cluster-scaling","type":2,"isActive":false},{"label":"How resource groups interacts with multiple replicas","href":"How-resource-groups-interacts-with-multiple-replicas","type":2,"isActive":false},{"label":"What's next","href":"Whats-next","type":1,"isActive":false}]} | ||
{"codeList":["{\n \"requests\": { \"nodeNum\": 1 },\n \"limits\": { \"nodeNum\": 1 },\n \"transfer_from\": [{ \"resource_group\": \"rg1\" }],\n \"transfer_to\": [{ \"resource_group\": \"rg2\" }]\n}\n","import pymilvus\n\n# A resource group name should be a string of 1 to 255 characters, starting with a letter or an underscore (_) and containing only numbers, letters, and underscores (_).\nname = \"rg\"\nnode_num = 0\n\n# create a resource group that exactly hold no query node.\ntry:\n milvus_client.create_resource_group(name, config=ResourceGroupConfig(\n requests={\"node_num\": node_num},\n limits={\"node_num\": node_num},\n ))\n print(f\"Succeeded in creating resource group {name}.\")\nexcept Exception:\n print(\"Failed to create the resource group.\")\n","rgs = milvus_client.list_resource_groups()\nprint(f\"Resource group list: {rgs}\")\n\n# Resource group list: ['__default_resource_group', 'rg']\n","info = milvus_client.describe_resource_group(name)\nprint(f\"Resource group description: {info}\")\n\n# Resource group description: \n# ResourceGroupInfo:\n# <name:rg1>, // resource group name\n# <capacity:0>, // resource group capacity\n# <num_available_node:1>, // resource group node num\n# <num_loaded_replica:{}>, // collection loaded replica num in resource group\n# <num_outgoing_node:{}>, // node num which still in use by replica in other resource group\n# <num_incoming_node:{}>, // node num which is in use by replica but belong to other resource group \n# <config:{}>, // resource group config\n# <nodes:[]> // node detail info\n","source = '__default_resource_group'\ntarget = 'rg'\nexpected_num_nodes_in_default = 0\nexpected_num_nodes_in_rg = 1\n\ntry:\n milvus_client.update_resource_groups({\n source: ResourceGroupConfig(\n requests={\"node_num\": expected_num_nodes_in_default},\n limits={\"node_num\": expected_num_nodes_in_default},\n ),\n target: ResourceGroupConfig(\n requests={\"node_num\": expected_num_nodes_in_rg},\n limits={\"node_num\": expected_num_nodes_in_rg},\n )\n })\n print(f\"Succeeded in move 1 node(s) from {source} to {target}.\")\nexcept Exception:\n print(\"Something went wrong while moving nodes.\")\n\n# After a while, succeeded in moving 1 node(s) from __default_resource_group to rg.\n","from pymilvus import Collection\n\ncollection_name = \"demo\"\n\n# Milvus loads the collection to the default resource group.\nmilvus_client.load_collection(collection_name, replica_number=2)\n\n# Or, you can ask Milvus load the collection to the desired resource group.\n# make sure that query nodes num should be greater or equal to replica_number\nresource_groups = ['rg']\nmilvus_client.load_collection(replica_number=2, _resource_groups=resource_groups) \n","collection = \"Books\"\npartition = \"Novels\"\n\n# Use the load method of a collection to load one of its partition\nmilvus_client.load_partitions(collection, [partition], replica_number=2, _resource_groups=resource_groups)\n","source = '__default_resource_group'\ntarget = 'rg'\ncollection_name = 'c'\nnum_replicas = 1\n\ntry:\n milvus_client.transfer_replica(source, target, collection_name, num_replicas)\n print(f\"Succeeded in moving {num_replicas} replica(s) of {collection_name} from {source} to {target}.\")\nexcept Exception:\n print(\"Something went wrong while moving replicas.\")\n\n# Succeeded in moving 1 replica(s) of c from __default_resource_group to rg.\n","resource_group = \"rg\ntry:\n milvus_client.update_resource_groups({\n resource_group: ResourceGroupConfig(\n requests={\"node_num\": 0},\n limits={\"node_num\": 0},\n ),\n })\n milvus_client.drop_resource_group(resource_group)\n print(f\"Succeeded in dropping {resource_group}.\")\nexcept Exception:\n print(f\"Something went wrong while dropping {resource_group}.\")\n","from pymilvus.client.types import ResourceGroupConfig\n\n_PENDING_NODES_RESOURCE_GROUP=\"__pending_nodes\"\n\ndef init_cluster(node_num: int):\n print(f\"Init cluster with {node_num} nodes, all nodes will be put in default resource group\")\n # create a pending resource group, which can used to hold the pending nodes that do not hold any data.\n milvus_client.create_resource_group(name=_PENDING_NODES_RESOURCE_GROUP, config=ResourceGroupConfig(\n requests={\"node_num\": 0}, # this resource group can hold 0 nodes, no data will be load on it.\n limits={\"node_num\": 10000}, # this resource group can hold at most 10000 nodes \n ))\n\n # update default resource group, which can used to hold the nodes that all initial node in it.\n milvus_client.update_resource_groups({\n \"__default_resource_group\": ResourceGroupConfig(\n requests={\"node_num\": node_num},\n limits={\"node_num\": node_num},\n transfer_from=[{\"resource_group\": _PENDING_NODES_RESOURCE_GROUP}], # recover missing node from pending resource group at high priority.\n transfer_to=[{\"resource_group\": _PENDING_NODES_RESOURCE_GROUP}], # recover redundant node to pending resource group at low priority.\n )})\n milvus_client.create_resource_group(name=\"rg1\", config=ResourceGroupConfig(\n requests={\"node_num\": 0},\n limits={\"node_num\": 0},\n transfer_from=[{\"resource_group\": _PENDING_NODES_RESOURCE_GROUP}], \n transfer_to=[{\"resource_group\": _PENDING_NODES_RESOURCE_GROUP}],\n ))\n milvus_client.create_resource_group(name=\"rg2\", config=ResourceGroupConfig(\n requests={\"node_num\": 0},\n limits={\"node_num\": 0},\n transfer_from=[{\"resource_group\": _PENDING_NODES_RESOURCE_GROUP}], \n transfer_to=[{\"resource_group\": _PENDING_NODES_RESOURCE_GROUP}],\n ))\n\ninit_cluster(1)\n","\ndef scale_to(node_num: int):\n # scale the querynode number in Milvus into node_num.\n pass\n","# scale rg1 into 3 nodes, rg2 into 1 nodes\nmilvus_client.update_resource_groups({\n \"rg1\": ResourceGroupConfig(\n requests={\"node_num\": 3},\n limits={\"node_num\": 3},\n transfer_from=[{\"resource_group\": _PENDING_NODES_RESOURCE_GROUP}],\n transfer_to=[{\"resource_group\": _PENDING_NODES_RESOURCE_GROUP}],\n ),\n \"rg2\": ResourceGroupConfig(\n requests={\"node_num\": 1},\n limits={\"node_num\": 1},\n transfer_from=[{\"resource_group\": _PENDING_NODES_RESOURCE_GROUP}],\n transfer_to=[{\"resource_group\": _PENDING_NODES_RESOURCE_GROUP}],\n ),\n})\nscale_to(5)\n# rg1 has 3 nodes, rg2 has 1 node, __default_resource_group has 1 node.\n","# scale rg1 from 3 nodes into 2 nodes\nmilvus_client.update_resource_groups({\n \"rg1\": ResourceGroupConfig(\n requests={\"node_num\": 2},\n limits={\"node_num\": 2},\n transfer_from=[{\"resource_group\": _PENDING_NODES_RESOURCE_GROUP}],\n transfer_to=[{\"resource_group\": _PENDING_NODES_RESOURCE_GROUP}],\n ),\n})\n\n# rg1 has 2 nodes, rg2 has 1 node, __default_resource_group has 1 node, __pending_nodes has 1 node.\nscale_to(4)\n# scale the node in __pending_nodes\n"],"headingContent":"Manage Resource Groups","anchorList":[{"label":"Manage Resource Groups","href":"Manage-Resource-Groups","type":1,"isActive":false},{"label":"What is a resource group","href":"What-is-a-resource-group","type":2,"isActive":false},{"label":"Concepts of resource group","href":"Concepts-of-resource-group","type":2,"isActive":false},{"label":"Use declarative api to manage resource group","href":"Use-declarative-api-to-manage-resource-group","type":2,"isActive":false},{"label":"A good practice to manage cluster scaling","href":"A-good-practice-to-manage-cluster-scaling","type":2,"isActive":false},{"label":"How resource groups interacts with multiple replicas","href":"How-resource-groups-interacts-with-multiple-replicas","type":2,"isActive":false},{"label":"What's next","href":"Whats-next","type":1,"isActive":false}]} |
Oops, something went wrong.