Skip to content

Commit 07f2e60

Browse files
sourcecdSergey J
andauthored
add some queue for nodes operations (#10620)
Co-authored-by: Sergey J <wint@yandex-team.ru>
1 parent 857b20e commit 07f2e60

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

ydb/tools/ydbd_slice/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ def deduce_nodes_from_args(args, walle_provider, ssh_user):
315315
sys.exit("unable to deduce hosts")
316316

317317
logger.info("use nodes '%s'", result)
318-
return nodes.Nodes(result, args.dry_run, ssh_user=ssh_user)
318+
return nodes.Nodes(result, args.dry_run, ssh_user=ssh_user, queue_size=args.cmd_queue_size)
319319

320320

321321
def ya_build(arcadia_root, artifact, opts, dry_run):
@@ -1187,6 +1187,13 @@ def main(walle_provider=None):
11871187
default="ver-01gswscgce37hdbqyssjm3nd7x",
11881188
help=''
11891189
)
1190+
parser.add_argument(
1191+
"--cmd-queue-size",
1192+
metavar="SIZE",
1193+
type=int,
1194+
default=0,
1195+
help='the size of the command queue (for ssh commands), which limits their parallel execution on remote nodes'
1196+
)
11901197

11911198
modes = parser.add_subparsers()
11921199
walle_provider = walle_provider or NopHostsInformationProvider()

ydb/tools/ydbd_slice/nodes.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@
22
import sys
33
import logging
44
import subprocess
5+
import queue
56

67

78
logger = logging.getLogger(__name__)
89

910

1011
class Nodes(object):
11-
def __init__(self, nodes, dry_run=False, ssh_user=None):
12+
def __init__(self, nodes, dry_run=False, ssh_user=None, queue_size=0):
1213
assert isinstance(nodes, list)
1314
assert len(nodes) > 0
1415
assert isinstance(nodes[0], str)
1516
self._nodes = nodes
1617
self._dry_run = bool(dry_run)
1718
self._ssh_user = ssh_user
1819
self._logger = logger.getChild(self.__class__.__name__)
20+
self._queue = queue.Queue(queue_size)
21+
self._qsize = queue_size
1922

2023
@property
2124
def nodes_list(self):
@@ -83,7 +86,23 @@ def execute_async_ret(self, cmd, check_retcode=True, nodes=None, results=None):
8386

8487
actual_cmd = self._get_ssh_command_prefix() + [host, cmd]
8588
process = subprocess.Popen(actual_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
89+
90+
if self._qsize > 0:
91+
self._queue.put((actual_cmd, process, host))
92+
if not self._queue.full():
93+
continue
94+
if not self._queue.empty():
95+
actual_cmd, process, host = self._queue.get()
96+
process.wait()
97+
8698
running_jobs.append((actual_cmd, process, host))
99+
100+
if self._qsize > 0:
101+
while not self._queue.empty():
102+
actual_cmd, process, host = self._queue.get()
103+
process.wait()
104+
running_jobs.append((actual_cmd, process, host))
105+
87106
return running_jobs
88107

89108
def execute_async(self, cmd, check_retcode=True, nodes=None, results=None):

0 commit comments

Comments
 (0)