I know web frameworks exist for Julia, but I’m wondering how practical it is to actually use this language for that purpose?
I know web frameworks exist for Julia, but I’m wondering how practical it is to actually use this language for that purpose?
But maybe I'm wrong here. It seems that "use the right tool" turns into use Python or JS or Excel for all the things.
Python had a long history of web server development. I think, aiohttp may be considered state of the art now. Let's measure its performance:
from aiohttp import web
async def handle(request):
return web.Response(text="Hello")
app = web.Application()
app.add_routes([web.get('/', handle),])
web.run_app(app)
using `wrk` for testing: $ wrk -t1 -c1000 -d30s http://127.0.0.1:8080/
Running 30s test @ http://127.0.0.1:8080/
1 threads and 1000 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 164.59ms 17.12ms 537.35ms 83.97%
Req/Sec 6.05k 0.95k 7.74k 74.33%
180749 requests in 30.08s, 26.72MB read
Requests/sec: 6008.75
Transfer/sec: 0.89MB
So we have ~6k rps on a single CPU core. As far as I remember, Tornado has ~4k rps, while built-in Flask server can process only about ~1k requests per second . Yes, you are unlikely to use Flask dev server in production, but for aiohttp it's indeed a recommended way.Now let's measure Julia's HTTP.jl server:
using HTTP
HTTP.listen() do request::HTTP.Request
return HTTP.Response("Hello")
end
which gives: $ wrk -t1 -c1000 -d30s http://127.0.0.1:8081/
Running 30s test @ http://127.0.0.1:8081/
1 threads and 1000 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 105.95ms 108.35ms 1.99s 98.40%
Req/Sec 9.65k 1.69k 13.66k 80.21%
271917 requests in 30.09s, 16.10MB read
Socket errors: connect 0, read 0, write 0, timeout 274
Requests/sec: 9035.73
Transfer/sec: 547.67KB
So it's 9k (with a few failed requests though).This doesn't include any routing, input data parsing, header or cookie processing, etc., but it amazes me how good the server is given that web development is NOT considered a strong part of the language.
The downside of Julia web programming is the number of libraries and tools (e.g. routers, DB connectors, template engines, etc.) - they exist, but are quite behind Python equivalents, so gotchas are expected. Yet I'm quite positive about future of web programming in Julia.
That said, my personal favourite thing about julia is not actually its speed but the fact that it's an incredibly expressive, flexible and composable language (I'd say julia learned all the mot important lessons lisp had to teach). If I had to guess, I'd think that building the infrastructure for devs to work on web servers from the ground up may very well be easier in julia than in most other langauges, including python. I may be off the mark though.
One other note since it was mentioned elsewhere, there actually is work being done right now to have julia compile to WebAssembly code which could be pretty cool!
However, it was pretty actively discouraged. I suspect they didn't want a lot of voices influencing the direction of the language while it was still being formed. A lot of what make R a poor general purpose language help make it effective in its specific domain for its specific users.
It might be worth people taking another look at it after 1.0 is released, as long as they have low expectations about influencing the direction of the language's development.
What is the specific context for this? Serving concurrent users? Or raw processing?
If it's the former, there are ways around this. If you'd like to replace Python for this, I'd look at something like Go rather than Julia.
If it's the latter, Julia might help, but there are a bunch of tradeoffs to consider. Julia is a language that was primarily designed for numerical computation.