tests/functional: Use more fine-grained locking when looking for free ports
PATCH 1/1 tests/functional: Use more fine-grained locking when looking for free ports
From: Thomas Huth <[email protected]>
Currently, we have one lock that is held while a test is looking for free ports. However, we are also using different ranges for looking for free ports nowadays (PORTS_START is based on the PID of the process), so instead of using only one lock, we should rather use a lock per range instead. This should help to allow running more tests in parallel.
While we're at it, also create the lock files without executable bit (mode is 0o777 by default).
--- tests/functional/qemu_test/ports.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
tests/functional/qemu_test/ports.py +3 -2
@@ -23,8 +23,9 @@ class Ports(): PORTS_END = PORTS_START + PORTS_RANGE_SIZE def __enter__(self): - lock_file = os.path.join(BUILD_DIR, "tests", "functional", "port_lock") - self.lock_fh = os.open(lock_file, os.O_CREAT) + lock_file = os.path.join(BUILD_DIR, "tests", "functional", + f".port_lock.{self.PORTS_START}") + self.lock_fh = os.open(lock_file, os.O_CREAT, mode=0o666) fcntl.flock(self.lock_fh, fcntl.LOCK_EX) return self
Signature · 1 line
2.50.1
Quoted 8 lines · Thomas Huth
From: Thomas Huth <[email protected]>
Currently, we have one lock that is held while a test is looking for free ports. However, we are also using different ranges for looking for free ports nowadays (
PORTS_STARTis based on the PID of the process), so instead of using only one lock, we should rather use a lock per range instead. This should help to allow running more tests in parallel.
Quoted 7 lines
While we're at it, also create the lock files without executable bit (mode is 0o777 by default).
Signed-off-by Thomas Huth <[email protected]>--- tests/functional/qemu_test/ports.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 12 lines · Thomas Huth
From: Thomas Huth <[email protected]>
Currently, we have one lock that is held while a test is looking for free ports. However, we are also using different ranges for looking for free ports nowadays (
PORTS_STARTis based on the PID of the process), so instead of using only one lock, we should rather use a lock per range instead. This should help to allow running more tests in parallel.While we're at it, also create the lock files without executable bit (mode is 0o777 by default).
(Unrelated to this patch but the file itself)
Hm. AF_INET supports binding to port 0 to connect to any available port (see man 7 ip). Is this not portable?
Quoted 25 lines
Signed-off-by Thomas Huth <[email protected]>--- tests/functional/qemu_test/ports.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)tests/functional/qemu_test/ports.py +3
-3@@ -23,8 +23,9 @@ class Ports(): PORTS_END = PORTS_START + PORTS_RANGE_SIZE def __enter__(self): - lock_file = os.path.join(BUILD_DIR, "tests", "functional", "port_lock") - self.lock_fh = os.open(lock_file, os.O_CREAT) + lock_file = os.path.join(BUILD_DIR, "tests", "functional", + f".port_lock.{self.PORTS_START}") + self.lock_fh = os.open(lock_file, os.O_CREAT, mode=0o666) fcntl.flock(self.lock_fh, fcntl.LOCK_EX) return self --2.50.1
Quoted 10 lines · Manos Pitsidianakis
Quoted 9 lines · Thomas Huth
From: Thomas Huth <[email protected]>
Currently, we have one lock that is held while a test is looking for free ports. However, we are also using different ranges for looking for free ports nowadays (
PORTS_STARTis based on the PID of the process), so instead of using only one lock, we should rather use a lock per range instead. This should help to allow running more tests in parallel.
Quoted 8 lines
Quoted 3 lines
While we're at it, also create the lock files without executable bit (mode is 0o777 by default).
(Unrelated to this patch but the file itself)
Hm.
AF_INETsupports binding to port 0 to connect to any available port (see man 7 ip). Is this not portable?
No clue ... but in that case, we'd need to go back to only use one lock for all tests that are running in parallel, so it might cause some more contention?
Thomas
Quoted 16 lines · Thomas Huth
Quoted 14 lines · Manos Pitsidianakis
Quoted 12 lines · Thomas Huth
From: Thomas Huth <[email protected]>
Currently, we have one lock that is held while a test is looking for free ports. However, we are also using different ranges for looking for free ports nowadays (
PORTS_STARTis based on the PID of the process), so instead of using only one lock, we should rather use a lock per range instead. This should help to allow running more tests in parallel.While we're at it, also create the lock files without executable bit (mode is 0o777 by default).
Quoted 7 lines
Quoted 4 lines
(Unrelated to this patch but the file itself)
Hm.
AF_INETsupports binding to port 0 to connect to any available port (see man 7 ip). Is this not portable?No clue ... but in that case, we'd need to go back to only use one lock for all tests that are running in parallel, so it might cause some more contention?
IIUC there would be no need for locking, since the kernel would return a free port for each process.
I can submit a patch btw, but thought I could ask first.
Signature · 2 lines
Manos Pitsidianakis Emulation and Virtualization Engineer at Linaro Ltd
Quoted 19 lines · Manos Pitsidianakis
Quoted 18 lines · Thomas Huth
Quoted 16 lines · Manos Pitsidianakis
Quoted 12 lines · Thomas Huth
From: Thomas Huth <[email protected]>
Currently, we have one lock that is held while a test is looking for free ports. However, we are also using different ranges for looking for free ports nowadays (
PORTS_STARTis based on the PID of the process), so instead of using only one lock, we should rather use a lock per range instead. This should help to allow running more tests in parallel.While we're at it, also create the lock files without executable bit (mode is 0o777 by default).
(Unrelated to this patch but the file itself)
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Hm.
AF_INETsupports binding to port 0 to connect to any available port (see man 7 ip). Is this not portable?No clue ... but in that case, we'd need to go back to only use one lock for all tests that are running in parallel, so it might cause some more contention?
IIUC there would be no need for locking, since the kernel would return a free port for each process.
That only works within a process, doesn't it? The problem here is that the test itself does not open the port, it just first needs to figure out a free port that will be used later. The test then launches QEMU with that port number, which will then open this port. Then the test connects to that port number (which it must know) to interact with QEMU. If QEMU is using port 0 for that, the test might not have a way to retrieve the final port number from QEMU in all cases.
Thomas
Quoted 39 lines · Thomas Huth
Quoted 19 lines · Manos Pitsidianakis
Quoted 18 lines · Thomas Huth
Quoted 16 lines · Manos Pitsidianakis
Quoted 12 lines · Thomas Huth
From: Thomas Huth <[email protected]>
Currently, we have one lock that is held while a test is looking for free ports. However, we are also using different ranges for looking for free ports nowadays (
PORTS_STARTis based on the PID of the process), so instead of using only one lock, we should rather use a lock per range instead. This should help to allow running more tests in parallel.While we're at it, also create the lock files without executable bit (mode is 0o777 by default).
(Unrelated to this patch but the file itself)
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Hm.
AF_INETsupports binding to port 0 to connect to any available port (see man 7 ip). Is this not portable?No clue ... but in that case, we'd need to go back to only use one lock for all tests that are running in parallel, so it might cause some more contention?
IIUC there would be no need for locking, since the kernel would return a free port for each process.
That only works within a process, doesn't it? The problem here is that the test itself does not open the port, it just first needs to figure out a free port that will be used later.
The test then launches QEMU with that port number, which will then open this port. Then the test connects to that port number (which it must know) to interact with QEMU.
If QEMU is using port 0 for that, the test might not have a way to retrieve the final port number from QEMU in all cases.
Quoted 2 lines
Thomas
Ah yeah, correct. It depends on what the test wants to do with that port.
Thanks
Signature · 2 lines
Manos Pitsidianakis Emulation and Virtualization Engineer at Linaro Ltd