Replace curl with little python script

This commit is contained in:
Tom Wilkie
2015-05-27 14:51:37 +00:00
parent 04145ce991
commit 8bccec8a78
7 changed files with 48 additions and 14 deletions

View File

@@ -14,3 +14,9 @@ goapp/app: goapp/app.go
clean:
rm -f qotd/*.o qotd/qotd goapp/app
run: all
docker-compose kill || true
docker-compose rm -f || true
docker-compose build
docker-compose up -d

View File

@@ -3,8 +3,7 @@
To run,
```
make
docker-compose up -d
make run
```
# "architecture"

View File

@@ -1,7 +1,7 @@
FROM gliderlabs/alpine
FROM python:2.7
MAINTAINER Weaveworks Inc <help@weave.works>
WORKDIR /home/weave
RUN apk add --update curl
ADD ./client /home/weave/
RUN chmod u+x /home/weave/client
ENTRYPOINT ["/home/weave/client"]
ADD requirements.txt /home/weave/
RUN pip install -r /home/weave/requirements.txt
ADD client.py /home/weave/
ENTRYPOINT ["python", "/home/weave/client.py"]

View File

@@ -1,6 +0,0 @@
#!/bin/sh
while true; do
curl http://pyapp:5000/
sleep 1
done

View File

@@ -0,0 +1,29 @@
import requests
import random
import threading
import logging
import sys
pyapps = ['http://pyapp:5000/']
concurrency = 5
def do_requests():
while True:
try:
requests.get(random.choice(pyapps))
except:
logging.error("Error doing request", exc_info=sys.exc_info())
logging.info("Did request")
def main():
logging.info("Starting %d thread", concurrency)
threads = [threading.Thread(target=do_requests) for i in range(concurrency)]
for thread in threads:
thread.start()
for thread in threads:
thread.join()
logging.info("Exiting")
if __name__ == "__main__":
logging.basicConfig()
main()

View File

@@ -0,0 +1,2 @@
requests

View File

@@ -1,6 +1,8 @@
import os
import socket
import requests
import random
from concurrent.futures import ThreadPoolExecutor
from flask import Flask
from redis import Redis
@@ -9,6 +11,8 @@ app = Flask(__name__)
redis = Redis(host='redis', port=6379)
pool = ThreadPoolExecutor(max_workers=10)
goapps = ['http://goapp1:8080/', 'http://goapp2:8080/']
def do_redis():
redis.incr('hits')
return redis.get('hits')
@@ -23,7 +27,7 @@ def do_qotd():
s.close()
def do_search():
r = requests.get('http://goapp:8080/')
r = requests.get(random.choice(goapps))
return r.text