-
Notifications
You must be signed in to change notification settings - Fork 857
TS-4341 #564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
TS-4341 #564
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9a14797
TS-4340: Fix origin max connections
bgaff 84e29a4
TS-4340 Add tests for per-origin connection limits
jacksontj 38aa266
TS-4341 add `origin_max_connections_queue`
jacksontj faf06b3
TS-4341 Document origin_max_connections_queue
jacksontj fa1bb29
TS-4342 Add tests for queued/max connections in addition to base tests
jacksontj 600a98e
Test for queue leaking in the CLIENT_ABORT case
jacksontj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,213 @@ | ||
| ''' | ||
| Test the configure entry : proxy.config.http.origin_max_connections | ||
| ''' | ||
|
|
||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import time | ||
| import logging | ||
| import uuid | ||
| import socket | ||
| import requests | ||
| import tsqa.test_cases | ||
| import helpers | ||
| import thread | ||
| from multiprocessing import Pool | ||
| import SocketServer | ||
| import os | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| # TODO: seems like a useful shared class- either add to httpbin or some shared lib | ||
| class KAHandler(SocketServer.BaseRequestHandler): | ||
| '''SocketServer that returns the connection-id as the body | ||
| ''' | ||
| # class variable to set number of active sessions | ||
| alive_sessions = 0 | ||
|
|
||
| def handle(self): | ||
| KAHandler.alive_sessions += 1 | ||
| # Receive the data in small chunks and retransmit it | ||
| conn_id = uuid.uuid4().hex | ||
| start = time.time() | ||
| while True: | ||
| data = self.request.recv(4096).strip() | ||
| if data: | ||
| log.info('Sending data back to the client: {uid}'.format(uid=conn_id)) | ||
| else: | ||
| log.info('Client disconnected: {timeout}seconds'.format(timeout=time.time() - start)) | ||
| break | ||
| body = conn_id | ||
| if 'timeout' in data: | ||
| print 'sleep for a long time!' | ||
| time.sleep(4) | ||
| else: | ||
| time.sleep(2) | ||
| resp = ('HTTP/1.1 200 OK\r\n' | ||
| 'Content-Length: {content_length}\r\n' | ||
| 'Content-Type: text/html; charset=UTF-8\r\n' | ||
| 'Connection: keep-alive\r\n' | ||
| 'X-Current-Sessions: {alive_sessions}\r\n' | ||
| '\r\n' | ||
| '{body}'.format(content_length=len(body), alive_sessions=KAHandler.alive_sessions, body=body)) | ||
| self.request.sendall(resp) | ||
| KAHandler.alive_sessions -= 1 | ||
|
|
||
|
|
||
| class TestKeepAlive_Origin_Max_connections(helpers.EnvironmentCase): | ||
| @classmethod | ||
| def setUpEnv(cls, env): | ||
| cls.traffic_server_host = '127.0.0.1' | ||
| cls.traffic_server_port = int(cls.configs['records.config']['CONFIG']['proxy.config.http.server_ports']) | ||
| cls.socket_server_port = int(tsqa.utils.bind_unused_port()[1]) | ||
|
|
||
| log.info("socket_server_port = %d" % (cls.socket_server_port)) | ||
| cls.server = tsqa.endpoint.SocketServerDaemon(KAHandler, port=cls.socket_server_port) | ||
| cls.server.start() | ||
| cls.server.ready.wait() | ||
|
|
||
| cls.socket_server_port2 = int(tsqa.utils.bind_unused_port()[1]) | ||
| cls.server2 = tsqa.endpoint.SocketServerDaemon(KAHandler, port=cls.socket_server_port2) | ||
| cls.server2.start() | ||
| cls.server2.ready.wait() | ||
|
|
||
| queue_path = os.path.join(cls.environment.layout.sysconfdir, 'queue.conf') | ||
| with open(queue_path, 'w') as fh: | ||
| fh.write('CONFIG proxy.config.http.origin_max_connections_queue INT 2') | ||
|
|
||
| noqueue_path = os.path.join(cls.environment.layout.sysconfdir, 'noqueue.conf') | ||
| with open(noqueue_path, 'w') as fh: | ||
| fh.write('CONFIG proxy.config.http.origin_max_connections_queue INT 0') | ||
|
|
||
| cls.configs['remap.config'].add_line('map /other/queue/ http://127.0.0.1:{0} @plugin=conf_remap.so @pparam={1}'.format(cls.socket_server_port2, queue_path)) | ||
| cls.configs['remap.config'].add_line('map /other/noqueue/ http://127.0.0.1:{0} @plugin=conf_remap.so @pparam={1}'.format(cls.socket_server_port2, noqueue_path)) | ||
| cls.configs['remap.config'].add_line('map /other/ http://127.0.0.1:{0}'.format(cls.socket_server_port2)) | ||
| cls.configs['remap.config'].add_line('map /queue/ http://127.0.0.1:{0} @plugin=conf_remap.so @pparam={1}'.format(cls.socket_server_port, queue_path)) | ||
| cls.configs['remap.config'].add_line('map /noqueue/ http://127.0.0.1:{0} @plugin=conf_remap.so @pparam={1}'.format(cls.socket_server_port, noqueue_path)) | ||
| cls.configs['remap.config'].add_line('map / http://127.0.0.1:{0}'.format(cls.socket_server_port)) | ||
|
|
||
| cls.configs['records.config']['CONFIG'].update({ | ||
| 'proxy.config.http.origin_max_connections': 1, | ||
| 'proxy.config.http.keep_alive_enabled_out': 1, | ||
| 'proxy.config.http.keep_alive_no_activity_timeout_out': 1, | ||
| 'proxy.config.http.transaction_active_timeout_out': 2, | ||
| 'proxy.config.http.connect_attempts_timeout': 2, | ||
| 'proxy.config.http.connect_attempts_rr_retries': 0, | ||
| 'proxy.config.exec_thread.limit': 1, | ||
| 'proxy.config.exec_thread.autoconfig': 0, | ||
| }) | ||
|
|
||
| def _send_requests(self, total_requests, path='', other=False): | ||
| url = 'http://{0}:{1}/{2}'.format(self.traffic_server_host, self.traffic_server_port, path) | ||
| url2 = 'http://{0}:{1}/other/{2}'.format(self.traffic_server_host, self.traffic_server_port, path) | ||
| jobs = [] | ||
| jobs2 = [] | ||
| pool = Pool(processes=4) | ||
| for _ in xrange(0, total_requests): | ||
| jobs.append(pool.apply_async(requests.get, (url,))) | ||
| if other: | ||
| jobs2.append(pool.apply_async(requests.get, (url2,))) | ||
|
|
||
| results = [] | ||
| results2 = [] | ||
| for j in jobs: | ||
| try: | ||
| results.append(j.get()) | ||
| except Exception as e: | ||
| results.append(e) | ||
|
|
||
| for j in jobs2: | ||
| try: | ||
| results2.append(j.get()) | ||
| except Exception as e: | ||
| results2.append(e) | ||
|
|
||
| return results, results2 | ||
|
|
||
|
|
||
| # TODO: enable after TS-4340 is merged | ||
| # and re-enable `other` for the remaining queueing tests | ||
| def tesst_origin_scoping(self): | ||
| '''Send 2 requests to loopback (on separate ports) and ensure that they run in parallel | ||
| ''' | ||
| results, results2 = self._send_requests(1, other=True) | ||
|
|
||
| # TS-4340 | ||
| # ensure that the 2 origins (2 different ports on loopback) were running in parallel | ||
| for i in xrange(0, REQUEST_COUNT): | ||
| self.assertEqual(int(results[i].get().headers['X-Current-Sessions']), 2) | ||
| self.assertEqual(int(results2[i].get().headers['X-Current-Sessions']), 2) | ||
|
|
||
| def test_origin_default_queueing(self): | ||
| '''By default we have no queue limit | ||
| ''' | ||
| REQUEST_COUNT = 4 | ||
| results, results2 = self._send_requests(REQUEST_COUNT) | ||
|
|
||
| for x in xrange(0, REQUEST_COUNT): | ||
| self.assertEqual(results[x].status_code, 200) | ||
| #self.assertEqual(results2[x].status_code, 200) | ||
|
|
||
| def test_origin_queueing(self): | ||
| '''If a queue is set, N requests are queued and the rest immediately fail | ||
| ''' | ||
| REQUEST_COUNT = 4 | ||
| results, results2 = self._send_requests(REQUEST_COUNT, path='queue/') | ||
|
|
||
| success = 0 | ||
| fail = 0 | ||
| for x in xrange(0, REQUEST_COUNT): | ||
| if results[x].status_code == 200: | ||
| success += 1 | ||
| else: | ||
| fail += 1 | ||
| self.assertEqual(success, 3) | ||
|
|
||
| def test_origin_queueing_timeouts(self): | ||
| '''Lets have some requests timeout and ensure that the queue is freed up | ||
| ''' | ||
| REQUEST_COUNT = 4 | ||
| results, results2 = self._send_requests(REQUEST_COUNT, path='queue/timeout') | ||
|
|
||
| success = 0 | ||
| fail = 0 | ||
| for x in xrange(0, REQUEST_COUNT): | ||
| if results[x].status_code == 200: | ||
| success += 1 | ||
| print 'success', x | ||
| else: | ||
| fail += 1 | ||
| self.assertEqual(fail, 4) | ||
|
|
||
| self.test_origin_queueing() | ||
|
|
||
| def test_origin_no_queueing(self): | ||
| '''If the queue is set to 0, all requests past the max immediately fail | ||
| ''' | ||
| REQUEST_COUNT = 4 | ||
| results, results2 = self._send_requests(REQUEST_COUNT, path='noqueue/') | ||
|
|
||
| success = 0 | ||
| fail = 0 | ||
| for x in xrange(0, REQUEST_COUNT): | ||
| if results[x].status_code == 200: | ||
| success += 1 | ||
| else: | ||
| fail += 1 | ||
| print 'results:', success, fail | ||
| self.assertEqual(success, 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,3 +25,4 @@ | |
|
|
||
|
|
||
| ConnectionCount ConnectionCount::_connectionCount; | ||
| ConnectionCountQueue ConnectionCountQueue::_connectionCount; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that this returns nothing/garbage in the ipv6 case-- as both lines in ipv6 simply add to
.band.c, but the method only returns.i.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That being said, it seems to do the same thing in
ats_ip_hash, which also seems like it wouldn't work :/There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zretis a union; it's the same data.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jpeach thanks for calling out my stupid, for whatever reason I read it as struct ;) So nevermind then-- we are all set :)