r/Python • u/Koratozarix • Jan 02 '25
Discussion Appropriate framework for thesis
Hi everyone!
I'm currently working on my bachelor's thesis in Computer and systems sciences. The focus of my thesis is a comparison of Java and Python in terms of performance and scalability when implementing REST APIs.
For this, I’m using Spring Boot on the Java side. However, I’m unsure which Python framework would be the best equivalent for this comparison. Ideally, it should support REST API development, have a strong community, and be well-suited for performance and scalability testing. So far, I’ve considered Django and Flask, but I’m open to suggestions.
I already know a bit of Flask, but it feels like Flask is a bit too small to offer a fair comparison to Spring Boot.
What do you guys think is the most suitable Python framework to compare with Spring Boot?
3
u/cgoldberg Jan 02 '25
I'm also curious what you are using for testing/benchmarking if you want to elaborate a little.
3
u/Koratozarix Jan 02 '25
I'm measuring response time and error rates during different amounts of requests to evaluate the performance and scalability. Using tools like K6, I want to simulate low, medium, and high loads to gather metrics such as average response time, percentiles (90th and 99th), throughput, and error rates.
Tell me if you have any thoughts/tips and I'll be happy to hear them!
5
u/cgoldberg Jan 02 '25
I used to do performance and scalability testing as my main job for many years. You are on the right track with your approach.
My only advice is to create workloads reflecting actual user flows. You want to model realistic usage patterns and run a combination of these to simulate real traffic. For example, say you have a complex API with many endpoints. You want to access all of them in the same ways users might, varying the data in the requests you send. Many people try to benchmark performance by just banging on one endpoint with the same request over and over. Doing that will probably get you very unrealistic results.
Good luck. This sounds like a fun project and you might get to leverage it into landing a nice Performance Engineering job! I suggest sharing your code and results on GitHub when you are done to use as a portfolio.
2
u/thisdude415 Jan 02 '25
On the Python side, FastAPI is probably the only fair comparison, if you plan to actually stress test the system. It's specifically made for RESTful APIs, whereas Django is more of a full web framework and Flask is a dead-simple general purpose backend web server framework. (Notably, Flask is a synchronous framework and will completely choke on, e.g., 100 simultaneous connections to an endpoint that does "sleep 1s, then return hello world"... but it will also only take about 7 lines of code TOTAL to do so -- and Quart, Flask's async sister, could do it in nearly the same 7 lines without issues; although in prod, flask on Gunicorn could I think be deployed with multithreading or multi workers to mitigate the flask sync issue)
In terms of Python web frameworks, it would be worth exploring (and writing about in your thesis!) a short history of web frameworks in Python, the difference between WSGI and ASGI, the limitations of Flask, the motivations for Quart, building up to the relatively recent development and release of FastAPI, which your analysis will show is the most fair comparison to SpringBoot.
And really, what you'd end up comparing, is Spring Boot (on Spring Web MVC on Embedded Tomcat/Netty) versus FastAPI (on Starlette on Unicorn). You'll be testing "whole stack" vs "whole stack" and should acknowledge it as such.
Some fun comparisons would be to stress test a few things:
round trip time and memory footprint for a "hello world" response
latency for "native" math (e.g., return the 1000th prime number using Sieve of Eratosthenes)
latency for "optimized" math (e.g., the same algorithm in vectorized NumPy operations, which will use C behind the scenes)
performance handling 1000s of connections at a time
and then measure memory footprint, latency, and lines of code, and total time you spent writing the functions for each of them.
You could even state you used an LLM to write the implementations and state that the use of AI tools are increasingly used within modern software engineering, so you asked Claude to implement these functions, counting the number of bugs and less-than-best practices you found in its implementation in each language, and adding this as an appendix.
For each of those performance comparisons, I would expect one language or the other to strongly outperform at each of these, so I think it will be a fun section of the paper for you to write.
1
1
1
-3
u/bubudumbdumb Jan 02 '25
To be honest Claude is good enough at churning out web server scaffolding and code.
You can aim at comparing 10 approaches not 2.
For python fast API is the leading choice now
17
u/cgoldberg Jan 02 '25
Besides Django, consider FastAPI also: https://fastapi.tiangolo.com/
It is very popular.