Skip to content

Instantly share code, notes, and snippets.

@matthewoliver
Created June 25, 2017 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewoliver/748eda73b527cf5f15911a10c606a3ca to your computer and use it in GitHub Desktop.
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.
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