-
Notifications
You must be signed in to change notification settings - Fork 60
Reuse socket #72
Reuse socket #72
Conversation
|
Cool! Thanks for taking this on. Honestly I think you're close to having a "good" design. A couple small changes would fix your limitations:
|
|
Thanks for the tips! Have a look and let me know what you think. |
|
Could you squash all the commits into one? |
488c81a to
9f4ab54
Compare
apoelstra
left a comment
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.
ACK 9f4ab54
|
We tried using this and something went wrong, so definitely don't merge this yet. I'll try to take a look at this over the weekend and figure out what exactly went wrong. |
697fcb4 to
c621b97
Compare
|
There were two problems:
We tested it with our application and everything works as it should now. So this would also close #67. |
tcharding
left a comment
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.
ACK c621b97
c621b97 to
1826d5e
Compare
|
ACK 1826d5e |
|
Gentle bump @apoelstra |
|
Yep, sorry -- let me test resyncing my homebrew wallet against Core with this change and then it can go in. |
|
|
||
| let content_length = content_length.ok_or(Error::HttpParseError)?; | ||
|
|
||
| let mut buffer = vec![0; content_length]; |
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.
We definitely need to put a limit on this, but it's fine for now :). We'll do a followup PR to audit this because I think get_line may also be subject to memory exhaustion attacks.
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.
yes, that sounds prudent
apoelstra
left a comment
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.
ACK 1826d5e
|
Hmm, with this PR I see a dramatic (~10x) slowdown in my syncing speed. My ACK still stands because we need to fix the Mac bug but we need to investigate this. |
|
Edit: a previous version of this comment said that there was still a 50-100% perf hit. This is because my laptop was unplugged and therefore throttled when I was doing the measurement. Ok, after modifying this PR to tighten the mutex lock's scope, in particular to unlock it before doing any parsing of the result, I get the same performance as before (possibly a small speedup, but I'm not measuring carefully enough to tell). I'm fine to move that to a followup PR as well. |
|
@raphjaph just fyi your CI fails are not your fault, will be resolved by: #74 (comment) |
|
@raphjaph can you rebase on master? We've fixed the CI. |
1826d5e to
e867374
Compare
Ok, that's good to know I'll do the performance stuff in a follow-up PR then. |
apoelstra
left a comment
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.
ACK e867374
2380d90 simple_http: eliminate confused `get_line` function; reuse buffer (Andrew Poelstra) 72bea34 simple_http: deserialize json from the reader, don't use an intermediate buffer (Andrew Poelstra) c20033e simple_http: add type ascriptions; fix incorrect mutexguard drop logic (Andrew Poelstra) 20da231 simple_http: store the BufReader rather than bare socket (Andrew Poelstra) 8d2ec83 add fuzzing harness for simple_http (Andrew Poelstra) f44a535 simple_http: mock out TcpStream when fuzzing (Andrew Poelstra) 2a0903e simple_http: handle large or missing Content-length headers correctly (Andrew Poelstra) e6eaedd simple_http: fix crash when receiving non-ascii HTTP hello (Andrew Poelstra) 7640a4b simple_http: split `HttpParseError` into several variants (Andrew Poelstra) 36708d6 simple_http: tighten mutex lifetime (Andrew Poelstra) Pull request description: Tightens the mutex lifetime to improve performance. Basically we read all the data into a buffer and then unlock the mutex ASAP. We could be a bit more memory-efficient by using `serde_json::from_reader` to parse directly from the socket, but (a) that would make it harder to enforce the Content-length header; and (b) it'd hold the mutex for longer than necessary. This commit also splits out the `HttpParseError` into several variants, which unfortunately makes this a breaking change. I think I can move that commit into its own PR if we want to get a minor rev out, but I don't think we care too much about that since this crate is pretty far to the edge of most dependency trees. Adds a fuzz harness but doesn't integrate it into CI. Fixes a couple bugs I found while fuzzing locally. ACKs for top commit: raphjaph: ACK 2380d90 tcharding: ACK 2380d90 Tree-SHA512: a7462434606f193c0736ebb74cb516d121dbd315db47a82754abb236b47ed744c2655729c407a98613e468f48a2fac025e5ccdab69e1e89395aeb0c2b2dfefca
This is a quick and dirty attempt at fixing #67 that reuses the socket for multiple requests. It has few issues:
SimpleHttpTransport::request()takes amutreference to self, which cascades to all downstream usersTcpStreamis notClone, therefore I had to remove the deriveCloneAn alternate implementation based on
reqwest(hyperseems too low-level because of the async stuff) wouldn't have these problems. So I think I'm going to start on that. Just wanted so share this draft PR if anyone has feedback or has an idea on how to do this withoutreqwest.