Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
misc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
misc
Commits
210f3221
Commit
210f3221
authored
Apr 28, 2016
by
Elvis Pranskevichus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add golang http implementation
parent
1854599f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
3 deletions
+62
-3
Dockerfile
Dockerfile
+4
-1
run_benchmarks
run_benchmarks
+6
-0
servers/.gitignore
servers/.gitignore
+1
-0
servers/asyncio_http_server.py
servers/asyncio_http_server.py
+12
-2
servers/gohttp.go
servers/gohttp.go
+39
-0
No files found.
Dockerfile
View file @
210f3221
...
@@ -10,6 +10,8 @@ ENV WORKON_HOME /usr/local/python-venvs
...
@@ -10,6 +10,8 @@ ENV WORKON_HOME /usr/local/python-venvs
ENV
GOMAXPROCS 1
ENV
GOMAXPROCS 1
RUN
mkdir
-p
/usr/local/python-venvs
RUN
mkdir
-p
/usr/local/python-venvs
RUN
mkdir
-p
/usr/go/
ENV
GOPATH /usr/go/
RUN
DEBIAN_FRONTEND
=
noninteractive
\
RUN
DEBIAN_FRONTEND
=
noninteractive
\
apt-get update
&&
apt-get
install
-y
\
apt-get update
&&
apt-get
install
-y
\
...
@@ -21,7 +23,8 @@ RUN vex --python=python3.5 -m bench pip install -U pip
...
@@ -21,7 +23,8 @@ RUN vex --python=python3.5 -m bench pip install -U pip
RUN
mkdir
-p
/var/lib/cache/pip
RUN
mkdir
-p
/var/lib/cache/pip
ADD
servers /usr/src/servers
ADD
servers /usr/src/servers
RUN
cd
/usr/src/servers
&&
go build goecho.go
RUN
cd
/usr/src/servers
&&
go build goecho.go
&&
\
go get github.com/golang/groupcache/lru
&&
go build gohttp.go
RUN
vex bench pip
--cache-dir
=
/var/lib/cache/pip
\
RUN
vex bench pip
--cache-dir
=
/var/lib/cache/pip
\
install
-r
/usr/src/servers/requirements.txt
install
-r
/usr/src/servers/requirements.txt
...
...
run_benchmarks
View file @
210f3221
...
@@ -181,6 +181,12 @@ benchmarks = [{
...
@@ -181,6 +181,12 @@ benchmarks = [{
'server'
:
nodejs
+
[
'/usr/src/servers/nodejs_http_server.js'
],
'server'
:
nodejs
+
[
'/usr/src/servers/nodejs_http_server.js'
],
'server_address'
:
tcp_address
,
'server_address'
:
tcp_address
,
'client'
:
http_client
,
'client'
:
http_client
,
},
{
'name'
:
'http-golang'
,
'title'
:
'HTTP server (golang)'
,
'server'
:
[
'/usr/src/servers/gohttp'
],
'server_address'
:
tcp_address
,
'client'
:
http_client
,
}]
}]
...
...
servers/.gitignore
View file @
210f3221
/goecho
/goecho
/gohttp
servers/asyncio_http_server.py
View file @
210f3221
...
@@ -13,6 +13,7 @@ from socket import *
...
@@ -13,6 +13,7 @@ from socket import *
PRINT
=
0
PRINT
=
0
_RESP_CACHE
=
{}
class
HttpRequest
:
class
HttpRequest
:
__slots__
=
(
'_protocol'
,
'_url'
,
'_headers'
,
'_version'
)
__slots__
=
(
'_protocol'
,
'_url'
,
'_headers'
,
'_version'
)
...
@@ -99,7 +100,11 @@ class HttpProtocol(asyncio.Protocol):
...
@@ -99,7 +100,11 @@ class HttpProtocol(asyncio.Protocol):
payload_size
=
1024
payload_size
=
1024
else
:
else
:
payload_size
=
int
(
payload_size
)
payload_size
=
int
(
payload_size
)
response
.
write
(
b'X'
*
payload_size
)
resp
=
_RESP_CACHE
.
get
(
payload_size
)
if
resp
is
None
:
resp
=
b'X'
*
payload_size
_RESP_CACHE
[
payload_size
]
=
resp
response
.
write
(
resp
)
self
.
_current_parser
=
None
self
.
_current_parser
=
None
self
.
_current_request
=
None
self
.
_current_request
=
None
...
@@ -112,7 +117,12 @@ def abort(msg):
...
@@ -112,7 +117,12 @@ def abort(msg):
def
aiohttp_server
(
loop
,
addr
):
def
aiohttp_server
(
loop
,
addr
):
async
def
handle
(
request
):
async
def
handle
(
request
):
payload_size
=
int
(
request
.
match_info
.
get
(
'size'
,
1024
))
payload_size
=
int
(
request
.
match_info
.
get
(
'size'
,
1024
))
return
web
.
Response
(
body
=
b'X'
*
payload_size
)
resp
=
_RESP_CACHE
.
get
(
payload_size
)
if
resp
is
None
:
resp
=
b'X'
*
payload_size
_RESP_CACHE
[
payload_size
]
=
resp
response
.
write
(
resp
)
return
web
.
Response
(
body
=
resp
)
app
=
web
.
Application
(
loop
=
loop
)
app
=
web
.
Application
(
loop
=
loop
)
app
.
router
.
add_route
(
'GET'
,
'/{size}'
,
handle
)
app
.
router
.
add_route
(
'GET'
,
'/{size}'
,
handle
)
...
...
servers/gohttp.go
0 → 100644
View file @
210f3221
package
main
import
(
"fmt"
"net/http"
"strconv"
"strings"
"github.com/golang/groupcache/lru"
)
var
cache
*
lru
.
Cache
func
handler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
var
resp
string
respSize
:=
r
.
URL
.
Path
[
1
:
]
s
,
err
:=
strconv
.
Atoi
(
respSize
)
if
err
!=
nil
{
s
=
1024
}
val
,
ok
:=
cache
.
Get
(
s
)
if
ok
{
resp
=
val
.
(
string
)
}
else
{
resp
=
strings
.
Repeat
(
"X"
,
s
)
cache
.
Add
(
s
,
resp
)
}
fmt
.
Fprintf
(
w
,
resp
)
}
func
main
()
{
cache
=
lru
.
New
(
10
)
http
.
HandleFunc
(
"/"
,
handler
)
fmt
.
Println
(
"Serving on :25000"
)
http
.
ListenAndServe
(
":25000"
,
nil
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment