Skip to content

Instantly share code, notes, and snippets.

@creationix
Last active October 29, 2015 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save creationix/f2ca3b8c99131926f577 to your computer and use it in GitHub Desktop.
Save creationix/f2ca3b8c99131926f577 to your computer and use it in GitHub Desktop.
local http = require("http")
local https = require("https")
local pathJoin = require('luvi').path.join
local fs = require('fs')
local timer = require('timer')
local snapshot = require('snapshot')
local S1
local i = 0
local function onRequest(req, res)
--print(req.socket.options and "https" or "http", req.method, req.url)
local body = "Hello world\n"
res:setHeader("Content-Type", "text/plain")
res:setHeader("Content-Length", #body)
res:finish(body)
collectgarbage()
timer.setTimeout(100, function ()
collectgarbage()
local S2 = snapshot()
print("Start " .. i)
local c = 0
for k,v in pairs(S2) do
if S1[k] == nil then
c = c + 1
p(k)
print(v)
end
end
S1 = S2
print("end " .. i .. "(" .. c .. ")")
i = i + 1
end)
end
http.createServer(onRequest):listen(8080)
print("Server listening at http://localhost:8080/")
https.createServer({
key = fs.readFileSync(pathJoin(module.dir, "key.pem")),
cert = fs.readFileSync(pathJoin(module.dir, "cert.pem")),
}, onRequest):listen(8443)
print("Server listening at https://localhost:8443/")
collectgarbage()
S1 = snapshot()
@creationix
Copy link
Author

Start 5
userdata: 0x073d5de0
table
0x752c770 : buffer

userdata: 0x074067d8
table
0x7430e00 : S1
0x741e628 : S1

userdata: 0x074221e8
[string "bundle:/deps/http.lua"]:264
0x7422290 : onTimeout
0x7422228 : onTimeout
0x7422cd0 : callback
0x74223a0 : callback

userdata: 0x074223a0
table
0x7422430 : [1]

userdata: 0x07422228
[string "bundle:/deps/http.lua"]:268
0x7422290 : onEnd
0x752cb08 : [1]

userdata: 0x074241b8
table
0x7423ee8 : buffer

userdata: 0x07423290
table
0x752cae0 : drain

userdata: 0x07422f18
[string "bundle:/deps/http-codec.lua"]:151
0x7423ec0 : encode

userdata: 0x07422f38
table
0x7423798 : bindArgs

userdata: 0x07423798
[string "bundle:/deps/utils.lua"]:49
0x7423158 : [1]

userdata: 0x073e91b8
table
0x737ed08 : [1]

userdata: 0x073e91f8
table
0x737ed08 : [2]

userdata: 0x0752cd80
table
0x752cae0 : finish

userdata: 0x0752cd18
[string "bundle:/deps/utils.lua"]:42
0x752cd80 : [1]

userdata: 0x0752c440
table
0x7423ec0 : socket
0x752cc00 : stream
0x74221e8 : socket
0x74223a0 : emitter
0x752cd18 : self
0x752c7c0 : self
0x7422290 : socket

userdata: 0x0752c468
table
0x752c440 : _readableState

userdata: 0x0752c558
table
0x752cae0 : _socketEnd

userdata: 0x07423ec0
table
0x7423798 : self
0x74231e0 : self
0x73e90d0 : self
0x7422290 : res
0x7424190 : stream

userdata: 0x07423ee8
table
0x7423ec0 : _writableState

userdata: 0x073e90d0
[string "bundle:/deps/utils.lua"]:49
0x752cb08 : [2]

userdata: 0x0752c4f0
table
0x752c468 : buffer

userdata: 0x0752d0e0
[string "bundle:/deps/http-codec.lua"]:244
0x7422010 : decodeChunked

userdata: 0x07422188
[string "bundle:/deps/http-codec.lua"]:283
0x7422290 : decode

userdata: 0x074221a8
[string "bundle:/deps/http.lua"]:259
0x7422290 : flush
0x7422228 : flush

userdata: 0x07422430
table
0x752cae0 : timeout

userdata: 0x07422800
table
0x752cae0 : data

userdata: 0x07422138
[string "bundle:/deps/http-codec.lua"]:238
0x7422010 : decodeRaw

userdata: 0x074231a0
table
0x74231e0 : bindArgs

userdata: 0x07422158
[string "bundle:/deps/http-codec.lua"]:259
0x7422010 : decodeCounted

userdata: 0x0752cb08
table
0x752cae0 : end

userdata: 0x07422010
[string "bundle:/deps/http-codec.lua"]:164
0x7422188 : mode
0x752d0e0 : decodeHead
0x74220f0 : decodeHead
0x7422010 : mode
0x7422158 : mode

userdata: 0x07424190
[string "bundle:/deps/stream/stream_writable.lua"]:126
0x7423ee8 : onwrite

userdata: 0x074232d8
table
0x73e90d0 : bindArgs

userdata: 0x07424580
[string "bundle:/deps/http-codec.lua"]:126
0x7422f18 : mode
0x74244e8 : encodeRaw
0x7424580 : mode
0x7422ef0 : mode

userdata: 0x074220f0
[string "bundle:/deps/http-codec.lua"]:233
0x7422010 : decodeEmpty
0x7422158 : decodeEmpty

userdata: 0x07423158
table
0x752cae0 : close

userdata: 0x0752c7c0
[string "bundle:/deps/utils.lua"]:42
0x752c558 : [1]

userdata: 0x0752cae0
table
0x752c440 : handlers

userdata: 0x07422cd0
table
0x73b2448 : [6]

userdata: 0x07422ef0
[string "bundle:/deps/http-codec.lua"]:134
0x74244e8 : encodeChunked

userdata: 0x0737ed08
table
0x7423ec0 : headers

userdata: 0x0752cc00
[string "bundle:/deps/stream/stream_writable.lua"]:126
0x752c770 : onwrite

userdata: 0x0752c770
table
0x752c440 : _writableState

userdata: 0x07422290
[string "bundle:/deps/http.lua"]:275
0x7422290 : onData
0x7422800 : [1]

userdata: 0x074231e0
[string "bundle:/deps/utils.lua"]:49
0x7423290 : [1]

userdata: 0x0752c2d0
userdata
0x752c440 : _handle

userdata: 0x074244e8
[string "bundle:/deps/http-codec.lua"]:95
0x7424580 : encodeHead
0x7422ef0 : encodeHead

userdata: 0x073e59e0
table
0x73a6368 : immediateQueue
0x73a67b0 : immediateQueue

end 5(48)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment