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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation for docker #158

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lachlangrose
Copy link

I have added a short description of how to get SnakeViz working inside a docker container. If you don't expose the correct ports SnakeViz will get a connection error.

I assume only ports 8080:8085 are possible for SnakeViz to use? Does this mean you are limited to a maximum of 5 cells that can be profiled? It might be worthwhile noting this somewhere.

Thanks

@jiffyclub
Copy link
Owner

Thanks for making a PR, I appreciate it!

The port situation is more complex than that and the behavior is a different depending on whether you're using the CLI or the %%snakeviz IPython magic.

When using the CLI SnakeViz can use any available port you specify using the -p/--port option in the CLI. By default it will try 8080, 8081, 8082, 8083, and 8084, followed by 5 more randomly selected ports in the range [8060, 8100]. Here's the function that selects ports to try:

snakeviz/snakeviz/cli.py

Lines 28 to 36 in 3e3cce0

def random_ports(port, n):
"""Generate a list of n random ports near the given port.
The first 5 ports will be sequential, and the remaining n-5 will be
randomly selected in the range [port-2*n, port+2*n].
"""
for i in range(min(5, n)):
yield port + i
for i in range(n-5):
yield max(1, port + random.randint(-2*n, 2*n))
By default it is called as random_port(8080, 10).

If you're profiling cells in a notebook using the %%snakeviz magic command it does not leave the snakeviz server running so it's not expected to leave ports in use. There's code in the IPython magic that specifically tries to make it so ports are available for reuse after running it, so in theory there's no limitation on the number of cells you can profile and view in a notebook. But you're correct that the only predictable ports it will try are 8080, 8081, 8082, 8083, and 8084.

So I better understand your situation, it sounds like you are running a jupyter notebook in a docker container and wanting to configure the container so that using the %%snakeviz magic works?

@lachlangrose
Copy link
Author

Hi,

Yes this is for running in a Docker container and I have configured it so that it works, by exposing the ports 8080-8085. When I only exposed 8080 it didn't let me run snakeviz on two cells, so that is why I assumed you were limited to 5 - but it might have been a timing thing.

I did see the random port function but it wasn't called from the ipymagic code so I didn't include it but it would be worthwhile noting in the documentation as well as any ports used for snakeviz inside docker would need to be added to the exposed port range.

I am just suggesting minor changes to the documentation so that anyone who wants to use snakeviz on a docker container can do it easily.

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants