Building A Twilio Endpoint Load Tester with Python, Go and A Developer’s Empathy
Time to read: 2 minutes
Here are a few bits of advice: Test code in production. Skip the code reviews. Ship the app before load testing it. With these helpful tips, you’ll be on your way to certain doom in no time.
Sai Yerram once had a brush with the perils of not load testing, and he’s built a Twilio load tester to help his fellow developers avoid the danger he once faced. He built the app with Python, Go and empathy.
Sure there’s frameworks to use, and languages Sai prefers. But. The motivation behind the load tester is Sai’s desire to give back to developers. “It’s essential that every developer possess empathy for their users and other developers.”
In that same vein, Sai empathizes with a teacher who bore the brunt of consequence from a, shall we say, impromptu load test gone wrong. Sai ran an education startup that allowed teachers to log student attendance via Twilio SMS. When the teacher gave out the wrong code for students to text, the impromptu load test was off and running.
An Impromptu Load Test
“One time, a professor gave an incorrect code to the classroom and the system responded with invalid code. Students thought they mistyped and would send multiple texts. Imagine 60+ students sending 3-4 times in a flash of 1-5 seconds,” said Sai. “[Each] invalid code sent via SMS, the system would log 10 lines in log files, create 4 records in database, reply via SMS and one email to the professor.”
With a few hundred texts in his inbox, and a few hundred emails, the professor was not very pleased. It was a learning opportunity for Sai, one he’s made the best of.
“We had comprehensive unit/integration testing but no good way to test flash loads with valid/invalid data and observe resource utilizations.” Now Sai has that tool at the ready, thanks to his recent love affair with Go, his Python expertise, and of course, his empathy.
The Learning Experience
“I was learning Go recently. I was drawn to its simplicity of writing concurrent programs and its ability to distribute binaries. It took me two days to write this program. I have been Python developer for some time, so I envisioned the entire thing in Python first, then searched for Go counterparts and stitched it together.”
Try it out yourself right here, or read about it below. Learn more about Sai, and his new company Tradewave, an automated trading platform for bitcoin exchanges.
The Load Tester
The goal of the script is to load test your twilio endpoint, just like a simple ab tester. You can pass json data to the endpoint (both valid and invalid) and see how it utilizes resources and get an estimate of costs of using twilio with high load. For e.g. You can send 5000 invalid requests and see how your server utilizes its resources (does it flood the log files, emails, database, costs of receiving/replying etc).
In order to run the script, make a copy of the sample ini files and then run
Once completed, it will print the results of the load testing along with costs of sending/receiving messages (sample response below)
Config INI
Contains information such as account token, load factors. Check ini files for more documentation.
Data INI
Contains data that needs to be sent to the endpoint. Check ini files for more documentation.
Tests
To run tests, make a copy of the sample ini files and then adjust values. Then run go test -v
TODO
Remove the data ini file and instead choose a simple file format (txt) by having each line as a json data row. We can then distribute data across the requests
Related Posts
Related Resources
Twilio Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.