Created
June 25, 2017 06:47
-
-
Save matthewoliver/748eda73b527cf5f15911a10c606a3ca to your computer and use it in GitHub Desktop.
benchmark reloading times in Swift - start a bunch of proxies on the same port (SO_REUSEPORT) then roll through very quickly terminate and recreate proxies processes.
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
import multiprocessing | |
import time | |
from swift.common.wsgi import run_wsgi | |
def start_daemon(conf_file='/etc/swift/proxy-server.conf', options={}): | |
run_wsgi(conf_file, 'proxy-server', **options) | |
def start_stopper(num=3, sleep=0.5): | |
queue = [] | |
try: | |
for i in range(num): | |
p = multiprocessing.Process(target=start_daemon) | |
p.start() | |
queue.append(p) | |
while True: | |
time.sleep(sleep) | |
p = queue.pop(0) | |
p.terminate() | |
p = multiprocessing.Process(target=start_daemon) | |
p.start() | |
queue.append(p) | |
finally: | |
for p in queue: | |
p.terminate() | |
if __name__ == "__main__": | |
start_stopper() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment