Skip to content

Conversation

robertknight
Copy link
Member

@robertknight robertknight commented Mar 23, 2018

Transition the QA/production Docker image to use Python 3 to run the h web app and workers.

supervisord still requires Python 2, so to avoid having to install Python 2 alongside Python 3, I have replaced it with a Golang implementation which has all the features we need.

After this hits QA we should do some sanity testing of important parts of the site and check memory/CPU usage. After this hits production we should keep an eye on memory and CPU usage stats.

If we need to roll back for any reason, we can revert these commits and redeploy, or even just re-deploy the previous Docker image from the deployment build page.

Image size stats

Sizes reported by docker inspect hypothesis/hypothesis:dev:

Image size (master): 154MB
Image size (this branch): 167MB

Testing

  1. Build the dev docker image using make docker
  2. Run the image in a new container using make run-docker
  3. Inspect the container and verify that processes are using the expected version of Python
[I] (h-py3)  ~/h/r/h > docker exec -it <ID of container> /bin/sh
~ $ ps aux 
PID   USER     TIME   COMMAND
    1 hypothes   0:00 {supervisord} /usr/bin/python2 /usr/bin/supervisord -c co
   11 hypothes   0:00 python /var/lib/hypothesis/bin/logger
   12 hypothes   0:00 {gunicorn} /usr/bin/python3.6 /usr/bin/gunicorn --name we
   13 hypothes   0:00 {gunicorn} /usr/bin/python3.6 /usr/bin/gunicorn --paste c
   14 hypothes   0:02 python -m h celery worker
   16 hypothes   0:00 nginx: master process nginx
   17 hypothes   0:00 nginx: worker process
   18 hypothes   0:00 nginx: worker process
   24 hypothes   0:01 {gunicorn} /usr/bin/python3.6 /usr/bin/gunicorn --paste c
   29 hypothes   0:02 {gunicorn} /usr/bin/python3.6 /usr/bin/gunicorn --name we
   35 hypothes   0:00 python -m h celery worker
   36 hypothes   0:00 python -m h celery worker
   44 hypothes   0:00 /bin/sh
   48 hypothes   0:00 ps aux
~ $ stat /proc/11/exe # check that "python" is Python 3
  File: '/proc/11/exe' -> '/usr/bin/python3.6'
  Size: 0         	Blocks: 0          IO Block: 1024   symbolic link
Device: a0h/160d	Inode: 1034058     Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (  102/hypothesis)   Gid: (  103/hypothesis)
Access: 2018-03-21 08:56:10.000000000
Modify: 2018-03-21 08:56:10.000000000
Change: 2018-03-21 08:56:10.000000000

~ $ 

@codecov
Copy link

codecov bot commented Mar 23, 2018

Codecov Report

Merging #4901 into master will decrease coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4901      +/-   ##
==========================================
- Coverage   97.02%   97.02%   -0.01%     
==========================================
  Files         444      444              
  Lines       24643    24672      +29     
  Branches     1320     1330      +10     
==========================================
+ Hits        23910    23938      +28     
- Misses        606      607       +1     
  Partials      127      127
Impacted Files Coverage Δ
h/activity/bucketing.py 96.42% <0%> (-1.01%) ⬇️
h/search/parser.py 100% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 99a9e9d...bd17b9d. Read the comment docs.

@seanh
Copy link
Member

seanh commented Mar 27, 2018

I wonder if we need to wait for a quiet time (e.g. when not so busy on groups work) to merge this...

@hmstepanek
Copy link
Contributor

That's prob not be a bad idea @seanh.

Dockerfile Outdated
@@ -18,7 +18,7 @@ RUN apk add --no-cache \
libffi \
libpq \
nginx \
python2 \
python3 \
Copy link
Contributor

Choose a reason for hiding this comment

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

If supervisor requires python2-do we still need to keep python2 here?

Copy link
Member Author

@robertknight robertknight Mar 28, 2018

Choose a reason for hiding this comment

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

The py2-pip dependency takes care of that. Strictly speaking this was redundant before.

@seanh
Copy link
Member

seanh commented Mar 28, 2018

Something to watch out for: the click library (which we use to implement the hypothesis CLI) has complicated problems with Python 3: http://click.pocoo.org/5/python3/. We should make sure that the CLI works correctly with Python 3, including when run via Jenkins.

@robertknight
Copy link
Member Author

I wonder if we need to wait for a quiet time (e.g. when not so busy on groups work) to merge this...

I agree it makes sense to pick a quiet time of day and sprint. I'd prefer to have a more definite timeline than "when we're done with groups work" so we can wrap this up. How about next Tuesday morning (London time) when it'll be the start of the sprint and fairly quiet traffic-wise?

If there is a problem, we can just revert the single commit here and schedule work for another time.

Something to watch out for: the click library (which we use to implement the hypothesis CLI) has complicated problems with Python 3: http://click.pocoo.org/5/python3/.

I'm using Python 3 in my local dev environment and haven't encountered issues with the CLI tools. I've also done some basic testing of critical commands (hypothesis {shell, migrate, search}) in the Docker image.

From reading the docs, the main issues flagged up are to do with CLI tools that read binary data from stdin/write to stdout. AFAIK, none of ours do. Regarding the section at the bottom about I/O encoding, Python is configured to use UTF-8 in the Docker image which also avoids several hazards.

@hmstepanek
Copy link
Contributor

I think the start of the sprint sounds good.

@seanh
Copy link
Member

seanh commented Mar 29, 2018

I'd like to wait at least another week from next Tuesday. I'd like some time to do a little Python 3 review of the code myself, but I'll be focusing on the groups stuff in the current sprint until end of Tuesday. The following Tuesday should work.

@robertknight
Copy link
Member Author

The following Tuesday should work.

OK, that's fine with me. Unless there are any objections I will mark Tuesday 10th April as 🐍🐍🐍-day.

@seanh seanh added the Python 3 Issues related to making our code Python 3-compatible label Apr 10, 2018
@robertknight
Copy link
Member Author

Thanks for the detailed investigation @seanh. I hadn't responded yet because I wanted to focus on other development tasks this week.

I personally don't think it is absolutely necessary to do everything on that list before we switch over, in particular updating all dependencies (which has its own risks) and trying to get pylint clean. However I'm happy to let you noodle a way for a while and see what issues you can find. I'm sure it will be educational 🙂

@robertknight
Copy link
Member Author

robertknight commented Jun 1, 2018

This may be useful to resolve the issue with supervisord still requiring Python 2 to be installed: https://github.com/ochinchina/supervisord (supervisord written in Go, and thus compiled to a static binary)

Run h and its dependencies using Python 3.

The stable version of supervisord (3.3.x) is not compatible with Python
3 so continue to install and run it with Python 2. This is due to be
resolved with supervisord v4.x.
The stable version of supervisord still requires Python 2. To avoid
having to install Python 2 alongside Python 3 for this one application,
use a Golang implementation instead [1].

This makes the Python 3 Docker image only 4MB instead of 40MB larger
than the Python 2 Docker image.

[1] https://github.com/ochinchina/supervisord
@stale
Copy link

stale bot commented Oct 9, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Used by https://github.com/probot/stale to label stale issues and pull requests before closing them label Oct 9, 2018
@stale stale bot closed this Oct 16, 2018
@seanh
Copy link
Member

seanh commented Oct 18, 2018

I've deleted the big checklist comments above and moved them to a new issue: #5384

@seanh seanh mentioned this pull request Oct 18, 2018
24 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Python 3 Issues related to making our code Python 3-compatible stale Used by https://github.com/probot/stale to label stale issues and pull requests before closing them WIP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants