async 처리되는 지 안되는지 확인하기위해서는 server코드도 중요하지만 request보내는 클라코드도 중요하다. 둘중 하나라도 잘못되면 테스트가 제대로 안되서 오해소지가 있다.
아래 코드로 python 3.5환경에서 requests library가 async로 잘 처리되는 것을 확인했다.
server
# packages from gevent import monkey;monkey.patch_all(thread=False, subprocess=False) import gevent from flask import Flask, request, Response from gevent.pywsgi import WSGIServer from logging.handlers import RotatingFileHandler import logging import werkzeug.serving import requests import json import resource import hashlib # local files # limit gate process to use fd count less than 1024 resource.setrlimit(resource.RLIMIT_NOFILE, (1024, 1024)) app = Flask(__name__) end_server = False secret = None @app.route("/do") def check_ip(): param = request.args.get("param", None) print("got {0}".format(param)) resp = requests.get("https://snarky.ca/how-the-heck-does-async-await-work-in-python-3-5") # resp = requests.get("http://www.naver.com") print("done {0}".format(param)) return resp.text if __name__ == "__main__": http = WSGIServer(("0.0.0.0", 9999), app, log=app.logger) http.serve_forever() end_server = True app.logger.info("Server will be closed")
|
test client
from gevent import monkey;monkey.patch_all(thread=False) import gevent import requests j = 0 host = "127.0.0.1:9999" def test(): global j try: d = requests.get("http://127.0.0.1:9999/do?param="+str(j)) print(d.text+str(j)) except Exception as e: print(e) pass pool = [] for i in range(0, 100): pool.append(gevent.spawn(test)) j += 1 gevent.sleep(0.1) gevent.joinall(pool)
|
'서버 교양' 카테고리의 다른 글
filebeat traceabck multiline config (0) | 2017.10.16 |
---|---|
logstash conf example (0) | 2017.10.13 |
Logstash install (0) | 2017.03.17 |
[펌] 인증 암호화와 해쉬 (0) | 2016.10.29 |
Docker overview (0) | 2015.06.13 |