'전체 글'에 해당되는 글 96건

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
블로그 이미지

시간을 거스르는자

ytkang86@gmail.com

,

If you use http request or something using socket in gevent spawn,
you should make a limit of file open count. use python resource. like this,

import resource
resource.setrlimit(resource.RLIMIT_NOFILE, (1024, 1024))

Otherwise, It will consume all your memory as much as it can by consuming all file count that it can consume as specified on limit.conf (/etc/security/limit.conf)

But requests still consumes a lot of memory.. I just decided to use tornado instead of flask+gevent+requests

'python' 카테고리의 다른 글

gevent monkey patch all, code location  (0) 2017.09.14
flask with gevent monkey patch all  (0) 2017.07.26
websocket with gunicorn  (0) 2017.03.03
gunicorn vs uwsgi  (0) 2017.01.20
flask async response  (0) 2017.01.04
블로그 이미지

시간을 거스르는자

ytkang86@gmail.com

,

aws api gate way

aws 2017. 3. 18. 01:14

삽질

- 허용된 request만 받고 싶을때 -> api key 이용 (Resources -> GET-> Method Request를 누르면 설정하는게 나온다)

https://www.gellock.com/2015/12/10/using-api-keys-with-aws-api-gateway/

그럼 여기나온데로 request 날릴때 해더에 x-api-key: apikey 를 보내야 허용된다.

'aws' 카테고리의 다른 글

AWS lambda 삽질 일기  (0) 2017.03.17
kinesis firehose 삽질일기  (0) 2017.03.16
How to EC2 disk and memory usage monitoring  (0) 2015.03.27
elasticache dump to file  (1) 2015.03.23
[ubuntu server instance] mytoon setting  (0) 2014.10.24
블로그 이미지

시간을 거스르는자

ytkang86@gmail.com

,