Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add luvit implementations for echo & http servers #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ENV GOPATH /usr/go/
RUN DEBIAN_FRONTEND=noninteractive \
apt-get update && apt-get install -y \
autoconf automake libtool build-essential \
python3 python3-pip git nodejs golang gosu
python3 python3-pip git nodejs golang gosu curl

RUN pip3 install vex
RUN vex --python=python3.5 -m bench pip install -U pip
Expand All @@ -30,6 +30,10 @@ RUN vex bench pip --cache-dir=/var/lib/cache/pip \

RUN vex bench pip freeze -r /usr/src/servers/requirements.txt

RUN curl -L https://github.com/luvit/lit/raw/master/get-lit.sh | sh
RUN ./lit make lit://luvit/luvit
RUN install -t /usr/bin -m 0755 ./luvit

EXPOSE 25000

VOLUME /var/lib/cache
Expand Down
13 changes: 13 additions & 0 deletions run_benchmarks
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ server_base = ['docker', 'run', '--rm', '-t', '-p', '25000:25000',

python = ['vex', 'bench', 'python']
nodejs = ['nodejs']
luvit = ['luvit']

echo_client = ['./echo_client', '--output-format=json']

Expand Down Expand Up @@ -147,6 +148,12 @@ benchmarks = [{
'--streams', '--uvloop'],
'server_address': unix_address,
'client': unix_client,
}, {
'name': 'tcpecho-luvit',
'title': 'TCP echo server (luvit)',
'server': luvit + ['/usr/src/servers/luvitecho.lua'],
'server_address': tcp_address,
'client': tcp_client,
}, {
'name': 'http-asyncio-aiohttp',
'title': 'HTTP server (asyncio/aiohttp)',
Expand Down Expand Up @@ -191,6 +198,12 @@ benchmarks = [{
'server': ['/usr/src/servers/gohttp'],
'server_address': tcp_address,
'client': http_client,
}, {
'name': 'http-luvit',
'title': 'HTTP server (luvit)',
'server': luvit + ['/usr/src/servers/luvit_http_server.lua'],
'server_address': tcp_address,
'client': http_client,
}]


Expand Down
23 changes: 23 additions & 0 deletions servers/luvit_http_server.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
local http = require('http')
local url = require('url')

responses = {}

http.createServer(function (req, res)
req.uri = url.parse(req.url)
local msize = 1024
local path = req.uri.pathname
if string.len(path) > 1 then
msize = tonumber(string.sub(path, 2))
end

if not responses[msize] then
responses[msize] = string.rep("X", msize)
end

res:setHeader("Content-Type", "text/plain")
res:setHeader("Content-Length", msize)
res:finish(responses[msize])
end):listen(25000, '0.0.0.0')

print('Server running at http://127.0.0.1:25000/')
27 changes: 27 additions & 0 deletions servers/luvitecho.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
local uv = require('uv')

-- Create listener socket
local server = uv.new_tcp()
server:bind('0.0.0.0', 25000)

server:listen(128, function(err)
-- Create socket handle for client
local client = uv.new_tcp()

-- Accept incoming connection
server:accept(client)

-- Relay data back to client
client:read_start(function(err, data)
if err then
client:close()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need a return after this close

return
end

if data then
client:write(data)
else
client:close()
end
end)
end)