Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up open port detection by running the checks as a single command #1782

Merged
merged 1 commit into from Aug 26, 2019

Conversation

bsideup
Copy link
Member

@bsideup bsideup commented Aug 24, 2019

While working on #1781 (and it is all about the ultra fast tests) I noticed that the port checks take quite some time.

This change will:

  1. Make external port checks run in parallel
  2. Make internal port checks run as a single docker exec command rather than NUM_PORTS * NUM_STRATEGIES commands (3, 6, 9...)

Measurements

Even for 1 port, it is:

Before (1,443ms):

22:32:02.699 INFO  馃惓 [nginx:1.9.4] - Creating container for image: nginx:1.9.4
22:32:02.875 INFO  馃惓 [nginx:1.9.4] - Starting container with ID: 28a8774b9f299851811fcd8bc900910f9a6cf148c95aa88bc3b57d69f0f50939
22:32:03.562 INFO  馃惓 [nginx:1.9.4] - Container nginx:1.9.4 is starting: 28a8774b9f299851811fcd8bc900910f9a6cf148c95aa88bc3b57d69f0f50939
22:32:03.583 DEBUG org.testcontainers.containers.ExecInContainerPattern - /interesting_knuth: Running "exec" command: /bin/sh -c cat /proc/net/tcp{,6} | awk '{print $2}' | grep -i :1f90
22:32:03.767 DEBUG org.testcontainers.containers.ExecInContainerPattern - /interesting_knuth: Running "exec" command: /bin/sh -c nc -vz -w 1 localhost 8080
22:32:03.950 DEBUG org.testcontainers.containers.ExecInContainerPattern - /interesting_knuth: Running "exec" command: /bin/bash -c </dev/tcp/localhost/8080
22:32:04.142 INFO  馃惓 [nginx:1.9.4] - Container nginx:1.9.4 started

After (1,060ms):

22:31:27.313 INFO  馃惓 [nginx:1.9.4] - Creating container for image: nginx:1.9.4
22:31:27.497 INFO  馃惓 [nginx:1.9.4] - Starting container with ID: 2ab798d807aed3dc15afead9ff7aef82e6ff5f95087d9bf1866893f5587cf553
22:31:28.180 INFO  馃惓 [nginx:1.9.4] - Container nginx:1.9.4 is starting: 2ab798d807aed3dc15afead9ff7aef82e6ff5f95087d9bf1866893f5587cf553
22:31:28.204 DEBUG org.testcontainers.containers.ExecInContainerPattern - /flamboyant_chaum: Running "exec" command: /bin/sh -c true &&  (cat /proc/net/tcp{,6} | awk '{print $2}' | grep -i :1f90 || nc -vz -w 1 localhost 8080 || /bin/bash -c '</dev/tcp/localhost/8080')
22:31:28.373 INFO  馃惓 [nginx:1.9.4] - Container nginx:1.9.4 started

@bsideup bsideup added this to the next milestone Aug 24, 2019
@bsideup bsideup requested a review from a team August 24, 2019 20:35
@@ -25,7 +25,9 @@
protected void waitUntilReady() {
final Set<Integer> externalLivenessCheckPorts = getLivenessCheckPorts();
if (externalLivenessCheckPorts.isEmpty()) {
log.debug("Liveness check ports of {} is empty. Not waiting.", waitStrategyTarget.getContainerInfo().getName());
if (log.isDebugEnabled()) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

waitStrategyTarget.getContainerInfo() will call Docker API in case of Docker Compose, and, if debug is disabled, it is unnecessary

@bsideup bsideup mentioned this pull request Aug 25, 2019
2 tasks
@bsideup bsideup merged commit 137c510 into master Aug 26, 2019
@delete-merged-branch delete-merged-branch bot deleted the faster_port_checks branch August 26, 2019 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants