-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
wrk improvements #174
wrk improvements #174
Changes from 8 commits
c776c64
c5a6701
852ce4f
e0a28ac
f3daecd
d187bc6
b20a101
5b97bd9
790025b
f498f71
3bc553c
dc1efcb
885bef3
47170c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Vapor | ||
|
||
let app = Application() | ||
|
||
app.get("plaintext") { request in | ||
return "Hello, world!" | ||
} | ||
|
||
app.start() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,15 +32,24 @@ extension HTTPStream { | |
|
||
func receiveLine() throws -> String { | ||
var line: String = "" | ||
func append(byte: Byte) { | ||
guard byte >= minimumValidAsciiCharacter else { return } | ||
|
||
func append(byte: Byte?) { | ||
guard let byte = byte else { | ||
return | ||
} | ||
guard byte >= minimumValidAsciiCharacter else { | ||
return | ||
} | ||
|
||
line.append(Character(byte)) | ||
} | ||
|
||
while | ||
let next = try receiveByte() | ||
where next != newLine | ||
&& !closed { | ||
var next: Byte? | ||
while next != newLine && !closed { | ||
repeat { | ||
next = try receiveByte() | ||
} while next == nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahhh, is this it where it'll keep trying until it has value? Would it be worth There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True...receiveByte could spin until it gets a byte.... that might be more logical. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ketzusaka And here. |
||
|
||
append(next) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ class HTTPStreamServer<StreamType: HTTPStream>: Server { | |
var delegate: Responder! | ||
|
||
func serve(responder: Responder, on host: String, at port: Int) throws { | ||
halt() | ||
self.delegate = responder | ||
|
||
try stream.bind(to: host, on: port) | ||
|
@@ -40,40 +39,35 @@ class HTTPStreamServer<StreamType: HTTPStream>: Server { | |
} | ||
|
||
private func handle(socket: HTTPStream) { | ||
do { | ||
try Background { | ||
var keepAlive = false | ||
repeat { | ||
let request: Request | ||
do { | ||
request = try socket.receive() | ||
} catch { | ||
Log.error("Error receiving request: \(error)") | ||
return | ||
} | ||
|
||
let response: Response | ||
do { | ||
response = try self.delegate.respond(request) | ||
} catch { | ||
Log.error("Error parsing response: \(error)") | ||
return | ||
} | ||
|
||
do { | ||
try socket.send(response, keepAlive: keepAlive) | ||
} catch { | ||
Log.error("Error sending response: \(error)") | ||
} | ||
|
||
keepAlive = request.supportsKeepAlive | ||
} while keepAlive && !socket.closed | ||
|
||
socket.close() | ||
var keepAlive = false | ||
|
||
repeat { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this not need to be dispatched to a new thread? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, Hummingbird dispatches it for us. That's where the huge speed gain we got was. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From Hummingbird: _ = try Strand {
connectionHandler(Socket(socketDescriptor: requestDescriptor))
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome, that's a really good catch! Half the dispatching is probably for the best 😄 |
||
let request: Request | ||
do { | ||
request = try socket.receive() | ||
} catch { | ||
Log.error("Error receiving request: \(error)") | ||
return | ||
} | ||
} catch { | ||
Log.error("Error accepting request in background: \(error)") | ||
} | ||
|
||
let response: Response | ||
do { | ||
response = try self.delegate.respond(request) | ||
} catch { | ||
Log.error("Error parsing response: \(error)") | ||
return | ||
} | ||
|
||
do { | ||
try socket.send(response, keepAlive: keepAlive) | ||
} catch { | ||
Log.error("Error sending response: \(error)") | ||
} | ||
|
||
keepAlive = request.supportsKeepAlive | ||
} while keepAlive && !socket.closed | ||
|
||
socket.close() | ||
} | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,9 @@ class ConfigTests: XCTestCase { | |
} | ||
|
||
#if Xcode | ||
let workDir = "/Users/tanner/Developer/vapor/vapor/Sources/VaporDev/" | ||
let workDir = "/Users/tanner/Developer/vapor/vapor/Sources/Development/" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure, but is it possible to generalize this somehow? Do environment variables like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I remember trying really hard to make it work to no avail. Maybe I should add a comment explaining why it needs to be there. |
||
#else | ||
let workDir = "Sources/VaporDev/" | ||
let workDir = "Sources/Development/" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 I like this name change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I kept getting confused with my projects that used Vapor and starting |
||
#endif | ||
|
||
func testSimple() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand the difference here., am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before, if the first byte(s) received were nil, it would assume end of line and return whatever it had. It looks like some requests (especially
wrk
) start with an empty byte. So the empty byte came in, this skipped and returned an empty string, the request line got parsed as invalid, then it was all wonky after that.Now it will only assumes the line is done when it gets a new line character, which seems to be more technically valid, and also totally fixed the InvalidComponents issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ketzusaka Here