The curious case of slow/fast grequests code - PyCon SG 2019

Published on: Monday, 11 November 2019

Speaker: Saurabh Hirani, Principal Devops Engineer

If you have made a single HTTP request in Python, you have probably used the requests module. If you have made concurrent HTTP requests in Python, you have probably used the grequests module. I ran into an issue in production which made a grequests based code execute HTTPS GET requests serially without utilising the concurrency goodness promised by grequests. What was more interesting is that depending on the Python modules installed on my system, the same codebase ran fast or slow. Tumbling down that rabbit hole made me understand Python profiling, function tracing, understanding how gevent works and opening a pull request to fix the issue with a gevent based Python module. In this talk, I want to share my learnings with the audience through a working dockerized demo which showcases the following stages for the same codebase while explaining why each stage behaves the way it does: Stage-0 - Trigger which led to the exploration - May run slow/fast for Python 2.7 and slow/fast for Python 3.7 depending on the modules installed on your system. Stage-1 - Baseline with dockerized environment - Runs fast both for Python 2.7 and Python 3.7 Stage-2 - Detection of slowness and verification - Runs slow both for Python 2.7 and Python 3.7 Stage-3 - Python 2.7 fix - Runs fast for Python 2.7 but slow for Python 3.7 Stage-4 - Python 3.7 fix - Patching a gevent based Python module which fixes the issue and makes Python 3.7 fast again.

About the speaker:

Hello - I am Saurabh Hirani - I have been working in the infrastructure automation and tooling domain since 2005. I am currently working as a Principal SRE at Autodesk, Singapore. Python is one of my go-to languages and and I really love the simplicity and power that it yields (pun intended :)). I am giving a talk - "The curios case of slow/fast grequests code" - in which we are going to unravel an interesting concurrency issue I ran into while porting a python 2.7 code to python 3.7 from AWS EC2 to AWS Lambda. We will see how the same codebase runs slow or fast depending on the Python interpreter version and the module environment. In the process we will learn more about Python profiling, tracing and take a peek under the hood of gevent and grequests.

Event Page: https://pycon.sg/

Produced by Engineers.SG

Organization