Use sessions for the pyapp -> goapp link too.

This commit is contained in:
Tom Wilkie
2015-05-27 16:06:04 +00:00
parent 649d6b9793
commit 5065223f68
2 changed files with 8 additions and 5 deletions

View File

@@ -5,7 +5,7 @@ client:
- pyapp
pyapp:
build: pyapp
ports:
expose:
- "5000"
links:
- qotd
@@ -20,7 +20,7 @@ redis:
image: redis
goapp1:
build: goapp
ports:
expose:
- "8080"
links:
- elasticsearch1
@@ -28,7 +28,7 @@ goapp1:
- elasticsearch3
goapp2:
build: goapp
ports:
expose:
- "8080"
links:
- elasticsearch1

View File

@@ -2,6 +2,7 @@ import os
import socket
import requests
import random
import threading
from concurrent.futures import ThreadPoolExecutor
from flask import Flask
@@ -10,6 +11,7 @@ from redis import Redis
app = Flask(__name__)
redis = Redis(host='redis', port=6379)
pool = ThreadPoolExecutor(max_workers=10)
sessions = threading.local()
goapps = ['http://goapp1:8080/', 'http://goapp2:8080/']
@@ -27,10 +29,11 @@ def do_qotd():
s.close()
def do_search():
r = requests.get(random.choice(goapps))
if getattr(sessions, 'session', None) == None:
sessions.session = requests.Session()
r = sessions.session.get(random.choice(goapps))
return r.text
@app.route('/')
def hello():
counter_future = pool.submit(do_redis)