Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit 11d81fb

Browse files
committed
fix the issue that CPU&MEM keeps increasing overtime
1 parent 999bb61 commit 11d81fb

6 files changed

Lines changed: 32 additions & 43 deletions

File tree

Dockerfile

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,16 @@
11
FROM alpine:edge
22
MAINTAINER Feng Honglin <hfeng@tutum.co>
33

4-
# Install tini, haproxy, pip and the dockercloud-haproxy python package:
5-
RUN apk --no-cache add \
6-
tini \
7-
haproxy \
8-
py-pip \
9-
&& apk --no-cache add --virtual deps git \
10-
&& pip install --upgrade \
11-
pip \
12-
&& apk del deps \
13-
# Clean up obsolete files:
14-
&& rm -rf \
15-
# Clean up any temporary files:
16-
/tmp/* \
17-
# Clean up the pip cache:
18-
/root/.cache \
19-
# Remove any compiled python files (compile on demand):
20-
`find / -regex '.*\.py[co]'`
4+
COPY . /haproxy-src
215

22-
COPY reload.sh /reload.sh
23-
COPY . haproxy-src/
24-
RUN cd /haproxy-src/ && \
25-
pip install . \
26-
# Clean up obsolete files:
27-
&& rm -rf \
28-
# Clean up any temporary files:
29-
/tmp/* \
30-
# Clean up the pip cache:
31-
/root/.cache \
32-
# Remove any compiled python files (compile on demand):
33-
`find / -regex '.*\.py[co]'`
6+
RUN apk update && \
7+
apk --no-cache add tini haproxy py-pip build-base python-dev ca-certificates && \
8+
cp /haproxy-src/reload.sh /reload.sh && \
9+
cd /haproxy-src && \
10+
pip install -r requirements.txt && \
11+
pip install . && \
12+
apk del build-base python-dev && \
13+
rm -rf "/tmp/*" "/root/.cache" `find / -regex '.*\.py[co]'`
3414

3515
ENV RSYSLOG_DESTINATION=127.0.0.1 \
3616
MODE=http \

haproxy/helper/cloud_link_helper.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
from multiprocessing.pool import ThreadPool
1+
from gevent.pool import Pool
22

33
from haproxy.config import SERVICE_NAME_MATCH
44
from haproxy.utils import get_uuid_from_resource_uri, fetch_remote_obj
55

66
LINKED_CONTAINER_CACHE = {}
77

8+
pool = Pool(size=5)
9+
810

911
def get_cloud_links(haproxy_container):
1012
links = _init_links(haproxy_container.linked_to_container)
@@ -41,7 +43,7 @@ def _get_new_added_link_uri(container_object_cache, links):
4143

4244

4345
def _get_container_object_from_uri(container_uris):
44-
pool = ThreadPool(processes=10)
46+
global pool
4547
container_objects = pool.map(fetch_remote_obj, container_uris)
4648
return container_objects
4749

haproxy/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
from haproxycfg import run_haproxy
1414
from utils import save_to_file
1515

16+
17+
from gevent import monkey
18+
monkey.patch_all()
19+
1620
dockercloud.user_agent = "dockercloud-haproxy/%s" % __version__
1721

1822
logger = logging.getLogger("haproxy")

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
python-dockercloud==1.0.3
22
docker-compose==1.6.0
3+
gevent==1.1.1

setup.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
from setuptools import setup, find_packages
66

7+
requirements = [
8+
"python-dockercloud >= 1.0.3, < 2",
9+
"docker-compose >= 1.6.0, <2"
10+
]
11+
712

813
def read(*parts):
914
path = os.path.join(os.path.dirname(__file__), *parts)
@@ -20,17 +25,14 @@ def find_version(*file_paths):
2025
raise RuntimeError('Unable to find version string.')
2126

2227

23-
with open('requirements.txt') as f:
24-
install_requires = f.read().splitlines()
25-
2628
with open('./test-requirements.txt') as test_reqs_txt:
2729
test_requirements = [line for line in test_reqs_txt]
2830

2931
setup(
3032
name='dockercloud-haproxy',
3133
version=find_version('haproxy', '__init__.py'),
3234
packages=find_packages(),
33-
install_requires=install_requires,
35+
install_requires=requirements,
3436
tests_require=test_requirements,
3537
entry_points={
3638
'console_scripts':

tests/test_legacy_links.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ rm_container web-a lb
7676
docker run -d --name web-a -e HOSTNAME="web-a" dockercloud/hello-world
7777
docker run -d --name lb --link web-a:web-a -e DEFAULT_SSL_CERT="$(awk 1 ORS='\\n' cert1.pem)" -p 443:443 haproxy
7878
wait_for_startup https://${DOCKER_HOST_IP}
79-
curl -sSfL --resolve web-a.org:443:${DOCKER_HOST_IP} https://web-a.org 2>&1 | grep -iF "SSL certificate problem" > /dev/null
79+
curl -sSfL --resolve web-a.org:443:${DOCKER_HOST_IP} https://web-a.org 2>&1> /dev/null && exit $?
8080
curl -sSfL --cacert ca1.pem --resolve web-a.org:443:${DOCKER_HOST_IP} https://web-a.org 2>&1 | grep -iF 'My hostname is web-a' > /dev/null
8181
echo
8282

@@ -86,9 +86,9 @@ docker run -d --name web-a -e HOSTNAME="web-a" dockercloud/hello-world
8686
docker run -d --name lb --link web-a:web-a -e DEFAULT_SSL_CERT="$(awk 1 ORS='\\n' cert1.pem)" -e CA_CERT="$(awk 1 ORS='\\n' ca0.pem)" -p 443:443 haproxy
8787
wait_for_startup https://${DOCKER_HOST_IP}
8888
echo " Sending request without certificate"
89-
curl -sSfL --cacert ca1.pem --resolve web-a.org:443:${DOCKER_HOST_IP} https://web-a.org 2>&1 > /dev/null | grep 'handshake' > /dev/null
89+
curl -sSfL --cacert ca1.pem --resolve web-a.org:443:${DOCKER_HOST_IP} https://web-a.org 2>&1 > /dev/null && exit $?
9090
echo " Sending request with a wrong certificate"
91-
curl -sSfL --cacert ca1.pem --cert cert1.pem --resolve web-a.org:443:${DOCKER_HOST_IP} https://web-a.org 2>&1 > /dev/null | grep 'alert unknown ca' > /dev/null
91+
curl -sSfL --cacert ca1.pem --cert cert1.pem --resolve web-a.org:443:${DOCKER_HOST_IP} https://web-a.org 2>&1 > /dev/null && exit $?
9292
echo " Sending request with the correct certificate"
9393
curl -sSfL --cacert ca1.pem --cert cert0.pem --resolve web-a.org:443:${DOCKER_HOST_IP} https://web-a.org 2>&1 | grep -iF 'My hostname is web-a' > /dev/null
9494
echo
@@ -98,7 +98,7 @@ rm_container web-a lb
9898
docker run -d --name web-a -e HOSTNAME="web-a" dockercloud/hello-world
9999
docker run -d --name lb --link web-a:web-a -e CERT_FOLDER="/certs/" -v $(pwd)/cert1.pem:/certs/cert1.pem -p 443:443 haproxy
100100
wait_for_startup https://${DOCKER_HOST_IP}
101-
curl -sSfL --resolve web-a.org:443:${DOCKER_HOST_IP} https://web-a.org 2>&1 | grep -iF "SSL certificate problem" > /dev/null
101+
curl -sSfL --resolve web-a.org:443:${DOCKER_HOST_IP} https://web-a.org 2>&1 > /dev/null && exit $?
102102
curl -sSfL --cacert ca1.pem --resolve web-a.org:443:${DOCKER_HOST_IP} https://web-a.org 2>&1 | grep -iF 'My hostname is web-a' > /dev/null
103103
echo
104104

@@ -108,9 +108,9 @@ docker run -d --name web-a -e HOSTNAME="web-a" dockercloud/hello-world
108108
docker run -d --name lb --link web-a:web-a -e CERT_FOLDER="/certs/" -v $(pwd)/cert1.pem:/certs/cert1.pem -e CA_CERT_FILE="/cacert/ca0.pem" -v $(pwd)/ca0.pem:/cacert/ca0.pem -p 443:443 haproxy
109109
wait_for_startup https://${DOCKER_HOST_IP}
110110
echo " Sending request without certificate"
111-
curl -sSfL --cacert ca1.pem --resolve web-a.org:443:${DOCKER_HOST_IP} https://web-a.org 2>&1 > /dev/null | grep 'handshake' > /dev/null
111+
curl -sSfL --cacert ca1.pem --resolve web-a.org:443:${DOCKER_HOST_IP} https://web-a.org 2>&1 > /dev/null && exit $?
112112
echo " Sending request with a wrong certificate"
113-
curl -sSfL --cacert ca1.pem --cert cert1.pem --resolve web-a.org:443:${DOCKER_HOST_IP} https://web-a.org 2>&1 > /dev/null | grep 'alert unknown ca' > /dev/null
113+
curl -sSfL --cacert ca1.pem --cert cert1.pem --resolve web-a.org:443:${DOCKER_HOST_IP} https://web-a.org 2>&1 > /dev/null && exit $?
114114
echo " Sending request with the correct certificate"c
115115
curl -sSfL --cacert ca1.pem --cert cert0.pem --resolve web-a.org:443:${DOCKER_HOST_IP} https://web-a.org 2>&1 | grep -iF 'My hostname is web-a' > /dev/null
116116
echo
@@ -132,9 +132,9 @@ docker run -d --name web-b -e HOSTNAME="web-b" -e VIRTUAL_HOST="https://web-b.or
132132
docker run -d --name lb --link web-a:web-a --link web-b:web-b -p 443:443 haproxy
133133
wait_for_startup https://${DOCKER_HOST_IP}
134134
curl -sSfL --cacert ca1.pem --resolve web-a.org:443:${DOCKER_HOST_IP} https://web-a.org 2>&1 | grep -iF 'My hostname is web-a' > /dev/null
135-
curl -sSfL --cacert ca2.pem --resolve web-a.org:443:${DOCKER_HOST_IP} https://web-a.org 2>&1 2>&1 | grep -iF "SSL certificate problem: self signed certificate" > /dev/null
135+
curl -sSfL --cacert ca2.pem --resolve web-a.org:443:${DOCKER_HOST_IP} https://web-a.org 2>&1 > /dev/null && exit $?
136136
curl -sSfL --cacert ca2.pem --resolve web-b.org:443:${DOCKER_HOST_IP} https://web-b.org 2>&1 | grep -iF 'My hostname is web-b' > /dev/null
137-
curl -sSfL --cacert ca1.pem --resolve web-b.org:443:${DOCKER_HOST_IP} https://web-b.org 2>&1 2>&1 | grep -iF "SSL certificate problem: self signed certificate" > /dev/null
137+
curl -sSfL --cacert ca1.pem --resolve web-b.org:443:${DOCKER_HOST_IP} https://web-b.org 2>&1 > /dev/null && exit $?
138138
echo
139139

140140
echo "=> Test multiple virtual host entries"

0 commit comments

Comments
 (0)