def main(): import meinheld import threading from multiprocessing import Process prepare_static('static/') with app.test_request_context(): initialize() port = int(os.environ.get("PORT", '5000')) def kill_all(): for w in workers: w.terminate() signal.signal(signal.SIGTERM, kill_all) def run(): #meinheld.spawn(subscribe_update) th = threading.Thread(target=subscribe_update) th.daemon = True th.start() meinheld.run(app.wsgi_app) meinheld.set_backlog(128) meinheld.set_keepalive(1) meinheld.listen(('0.0.0.0', port)) meinheld.set_access_logger(None) workers = [] for i in xrange(6): w = Process(target=run) w.start() workers.append(w) while True: for w in workers: w.join(1)
for i in xrange(num_queries): world = connection.execute("SELECT * FROM World WHERE id=%s", (rp(), )).fetchone() randomNumber = rp() worlds.append({'id': world['id'], 'randomNumber': randomNumber}) connection.execute("UPDATE World SET randomNumber=%s WHERE id=%s", (randomNumber, world['id'])) return json_response(worlds) finally: connection.close() @app.route('/plaintext') def plaintext(): """Test 6: Plaintext""" response = make_response(b'Hello, World!') response.content_type = 'text/plain' return response try: import meinheld meinheld.server.set_access_logger(None) meinheld.set_keepalive(120) except ImportError: pass # entry point for debugging if __name__ == "__main__": app.run(debug=True)
rp = partial(randint, 1, 10000) for i in xrange(num_queries): world = connection.execute("SELECT * FROM World WHERE id=%s", (rp(),)).fetchone() randomNumber = rp() worlds.append({"id": world["id"], "randomNumber": randomNumber}) connection.execute("UPDATE World SET randomNumber=%s WHERE id=%s", (randomNumber, world["id"])) return json_response(worlds) finally: connection.close() @app.route("/plaintext") def plaintext(): """Test 6: Plaintext""" response = make_response(b"Hello, World!") response.content_type = "text/plain" return response try: import meinheld meinheld.server.set_access_logger(None) meinheld.set_keepalive(120) except ImportError: pass # entry point for debugging if __name__ == "__main__": app.run(debug=True)
# coding: utf-8 import meinheld meinheld.server.set_access_logger(None) meinheld.set_keepalive(30)
def configure(): meinheld.set_keepalive(int(os.getenv('KEEP_ALIVE', 120))) # timeout in seconds
return [response] def app(environ, start_response): path = environ['PATH_INFO'] if path.startswith('/json-response'): return request_json(environ, start_response) else: return request_json(environ, start_response) if __name__ == "__main__": import logging import os logging.disable(logging.CRITICAL) logger = logging.getLogger() logger.setLevel(logging.CRITICAL) logger.disabled = True logger.propagate = False import meinheld import meinheld.server meinheld.set_access_logger(None) meinheld.set_error_logger(None) meinheld.server.set_access_logger(None) meinheld.set_keepalive(int(os.getenv('KEEP_ALIVE', 120))) meinheld.server.listen(("0.0.0.0", int(os.getenv('PORT', 8000)))) meinheld.server.run(app)