Code Monkey home page Code Monkey logo

python-async-concurrent-requests's Introduction

python-async-concurrent-requests

A simple python script that allows for concurrent post requests by using async and await functionality with the help of the asyncio and aiohttp modules. I am using python version 3.7.

Asyncio is native to python after version 3.5 so there is no need to do a pip install if you are running python at that version or higher but aiohttp does have to be pip installed. The concurrent_requests.py file is the file doing the asynchronous concurrent post requests. The number of requests can be adjusted on line 122 in the run() function (currently I have it set to 10). The file server.py is a simple flask server (flask has to be pip installed) with one post route that accepts headers and a payload. Fire up the server by opening one command line window (terminal, cmd, etc), change directories to be in the directory with these files, and run python server.py. Then open up another command line window and run python concurrent_requests.py in the same directory to fire off the concurrent calls. Below is an example of this concurrent behavior. Async Concurrent Python calls

A quick backstory to why I set this simple repo up. I work as a software developer and one of our servers started giving us unexpected 502 errors every so often. This was due to an increased number of calls to that server but since it wasn't consistent we had to figure out why and how it was happening. This led to the task to developing a script that could do an X amount of calls at the same time. My coworker was able to easily set this beavior up with a newer programming language called Elixir since it is specifically designed to easily run thousands of processes at the same time. I wanted to do it in python since most of my coworkers are familiar with python. Once I had my script ready, I kept increasing the number of concurrent calls until we figured out the number that would cause our server to fail, which allowed us to make accomodations.

Test the limits of your own servers by increasing the number of calls! I used this article as a reference.

python-async-concurrent-requests's People

Contributors

marioaburto10 avatar

Stargazers

WebClinic avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.