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 Read/Write::can_read/write_vectored #67841

Merged
merged 6 commits into from
Apr 28, 2020
Merged

Conversation

sfackler
Copy link
Member

@sfackler sfackler commented Jan 3, 2020

When working with an arbitrary reader or writer, code that uses vectored
operations may end up being slower than code that copies into a single
buffer when the underlying reader or writer doesn't actually support
vectored operations. These new methods allow you to ask the reader or
witer up front if vectored operations are efficiently supported.

Currently, you have to use some heuristics to guess by e.g. checking if
the read or write only accessed the first buffer. Hyper is one concrete
example of a library that has to do this dynamically:
https://github.com/hyperium/hyper/blob/0eaf304644a396895a4ce1f0146e596640bb666a/src/proto/h1/io.rs#L582-L594

@rust-highfive
Copy link
Collaborator

r? @KodrAus

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 3, 2020
@sfackler
Copy link
Member Author

sfackler commented Jan 3, 2020

cc @nikomatsakis this is part of what we talked about when discussing buffer initialization and vectored IO.

/// If a `Read`er does not override the default `read_vectored`
/// implementation, code using it may want to avoid the method all together
/// and coalesce writes into a single buffer for higher performance.
#[unstable(feature = "can_vector", issue = "none")]
Copy link
Member Author

Choose a reason for hiding this comment

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

I'll fill in the issue assuming people are happy with this approach.

@nagisa
Copy link
Member

nagisa commented Jan 6, 2020

Why not just transparently merge the buffers? At this point the support for vectored I/O is becoming complicated enough that I think a broader discussion is worthwhile (i.e. an RFC).

Also the name is not great. can_*_vectored implies that the feature will always fail to work at all if this returns false whereas the real intent of this function is just to signal native support and throughput capabilities of vectored I/O.

@sfackler
Copy link
Member Author

sfackler commented Jan 6, 2020

Why not just transparently merge the buffers?

Because user code has more flexibility around how to merge those buffers.

Also the name is not great.

Sure - definitely open to better naming.

@KodrAus
Copy link
Contributor

KodrAus commented Jan 6, 2020

This seems reasonable to me.

Also the name is not great.

Perhaps something along the lines of the runtime CPU checks?

let strategy = if writer.is_write_vectored_optimized() {
    WriteStrategy::Queue
} else {
    WriteStrategy::Flatten
};

Also not a really great name, but the is_ prefix seems more in line with other branching methods.

@Dylan-DPC-zz Dylan-DPC-zz added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 16, 2020
@Dylan-DPC-zz
Copy link

@sfackler any updates?

@sfackler
Copy link
Member Author

is_write_vectored_optimized is a bit wordy, but works for me. It could be shortened to is_write_vectored potentially? It's all unstable so it doesn't matter too much right now.

@joelpalmer

This comment has been minimized.

@KodrAus
Copy link
Contributor

KodrAus commented Mar 11, 2020

I'd be on board with is_*_vectored too.

@sfackler
Copy link
Member Author

Renamed, and added a tracking issue

@rust-highfive
Copy link
Collaborator

The job mingw-check of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2020-03-12T01:03:41.1405515Z ========================== Starting Command Output ===========================
2020-03-12T01:03:41.1424806Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/7cb7b642-d728-414d-9095-0bf46407a825.sh
2020-03-12T01:03:41.3577165Z 
2020-03-12T01:03:41.3665341Z ##[section]Finishing: Disable git automatic line ending conversion
2020-03-12T01:03:41.3690771Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/67841/merge to s
2020-03-12T01:03:41.3698737Z Task         : Get sources
2020-03-12T01:03:41.3699071Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-03-12T01:03:41.3699403Z Version      : 1.0.0
2020-03-12T01:03:41.3699632Z Author       : Microsoft
---
2020-03-12T01:03:43.7169019Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-03-12T01:03:43.7320637Z ##[command]git config gc.auto 0
2020-03-12T01:03:43.7359922Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-03-12T01:03:43.7385968Z ##[command]git config --get-all http.proxy
2020-03-12T01:03:43.7496858Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/67841/merge:refs/remotes/pull/67841/merge
---
2020-03-12T01:09:54.7394874Z     Checking panic_unwind v0.0.0 (/checkout/src/libpanic_unwind)
2020-03-12T01:09:55.8777993Z error[E0407]: method `can_read_vectored` is not a member of trait `io::Read`
2020-03-12T01:09:55.8779811Z    --> src/libstd/sys/unix/ext/net.rs:617:5
2020-03-12T01:09:55.8780880Z     |
2020-03-12T01:09:55.8782060Z 617 | /     fn can_read_vectored(&self) -> bool {
2020-03-12T01:09:55.8783965Z 618 | |         io::Read::can_read_vectored(&&*self)
2020-03-12T01:09:55.8786741Z     | |_____^ not a member of trait `io::Read`
2020-03-12T01:09:55.8790602Z 
2020-03-12T01:09:55.8798536Z error[E0407]: method `can_read_vectored` is not a member of trait `io::Read`
2020-03-12T01:09:55.8799519Z    --> src/libstd/sys/unix/ext/net.rs:638:5
---
2020-03-12T01:09:55.8808688Z 
2020-03-12T01:09:57.7755833Z error[E0599]: no function or associated item named `can_read_vectored` found for trait object `dyn io::Read` in the current scope
2020-03-12T01:09:57.7756959Z    --> src/libstd/sys/unix/ext/net.rs:618:19
2020-03-12T01:09:57.7757572Z     |
2020-03-12T01:09:57.7758325Z 618 |         io::Read::can_read_vectored(&&*self)
2020-03-12T01:09:57.7759960Z     |                   |
2020-03-12T01:09:57.7760924Z     |                   function or associated item not found in `dyn io::Read`
2020-03-12T01:09:57.7762073Z     |                   help: there is a method with a similar name: `is_read_vectored`
2020-03-12T01:09:57.7762543Z 
---
2020-03-12T01:09:57.7796082Z     |
2020-03-12T01:09:57.7796731Z 21  | pub struct Socket(FileDesc);
2020-03-12T01:09:57.7797830Z     | ---------------------------- method `can_read_vectored` not found for this
2020-03-12T01:09:57.7798274Z 
2020-03-12T01:09:57.7827262Z error[E0599]: no method named `can_write_vectored` found for struct `sys::unix::net::Socket` in the current scope
2020-03-12T01:09:57.7828823Z     |
2020-03-12T01:09:57.7828823Z     |
2020-03-12T01:09:57.7829521Z 680 |         self.0.can_write_vectored()
2020-03-12T01:09:57.7830689Z     |                ^^^^^^^^^^^^^^^^^^ help: there is a method with a similar name: `is_write_vectored`
2020-03-12T01:09:57.7832211Z    ::: src/libstd/sys/unix/net.rs:21:1
2020-03-12T01:09:57.7832806Z     |
2020-03-12T01:09:57.7833472Z 21  | pub struct Socket(FileDesc);
2020-03-12T01:09:57.7833472Z 21  | pub struct Socket(FileDesc);
2020-03-12T01:09:57.7834465Z     | ---------------------------- method `can_write_vectored` not found for this
2020-03-12T01:09:58.0171999Z error: aborting due to 5 previous errors
2020-03-12T01:09:58.0177531Z 
2020-03-12T01:09:58.0178431Z Some errors have detailed explanations: E0407, E0599.
2020-03-12T01:09:58.0179123Z For more information about an error, try `rustc --explain E0407`.
---
2020-03-12T01:09:58.0404575Z   local time: Thu Mar 12 01:09:58 UTC 2020
2020-03-12T01:09:58.3289300Z   network time: Thu, 12 Mar 2020 01:09:58 GMT
2020-03-12T01:09:58.3289932Z == end clock drift check ==
2020-03-12T01:09:59.3536898Z 
2020-03-12T01:09:59.3603387Z ##[error]Bash exited with code '1'.
2020-03-12T01:09:59.3621777Z ##[section]Finishing: Run build
2020-03-12T01:09:59.3673584Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/67841/merge to s
2020-03-12T01:09:59.3678362Z Task         : Get sources
2020-03-12T01:09:59.3678709Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-03-12T01:09:59.3679046Z Version      : 1.0.0
2020-03-12T01:09:59.3679268Z Author       : Microsoft
2020-03-12T01:09:59.3679268Z Author       : Microsoft
2020-03-12T01:09:59.3679621Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
2020-03-12T01:09:59.3680049Z ==============================================================================
2020-03-12T01:09:59.7322377Z Cleaning any cached credential from repository: rust-lang/rust (GitHub)
2020-03-12T01:09:59.7368549Z ##[section]Finishing: Checkout rust-lang/rust@refs/pull/67841/merge to s
2020-03-12T01:09:59.7471974Z Cleaning up task key
2020-03-12T01:09:59.7473360Z Start cleaning up orphan processes.
2020-03-12T01:09:59.7677973Z Terminate orphan process: pid (3755) (python)
2020-03-12T01:09:59.7835613Z ##[section]Finishing: Finalize Job

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @rust-lang/infra. (Feature Requests)

@bors
Copy link
Contributor

bors commented Mar 17, 2020

☔ The latest upstream changes (presumably #70062) made this pull request unmergeable. Please resolve the merge conflicts.

@joelpalmer joelpalmer added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 30, 2020
@Dylan-DPC-zz
Copy link

@sfackler you have a merge commit. Can you unmerge it and rebase instead? thanks

@sfackler
Copy link
Member Author

Fixed

@Dylan-DPC-zz Dylan-DPC-zz added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 31, 2020
@Dylan-DPC-zz
Copy link

@KodrAus this is ready for review

@bors
Copy link
Contributor

bors commented Apr 4, 2020

☔ The latest upstream changes (presumably #70136) made this pull request unmergeable. Please resolve the merge conflicts.

@joelpalmer joelpalmer added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 14, 2020
@bors
Copy link
Contributor

bors commented Apr 26, 2020

📌 Commit 5d8fe1c has been approved by Amanieu

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 26, 2020
@bors
Copy link
Contributor

bors commented Apr 26, 2020

⌛ Testing commit 5d8fe1c with merge dd0bfd08f17cebeefea8fe2ae716edc78d3bd088...

@Dylan-DPC-zz
Copy link

@bors retry (yield)

@bors
Copy link
Contributor

bors commented Apr 26, 2020

⌛ Testing commit 5d8fe1c with merge c2f3b75ad1ed2899a39346f3cfe57930fc8f914a...

@bors
Copy link
Contributor

bors commented Apr 26, 2020

💔 Test failed - checks-azure

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 26, 2020
@sfackler
Copy link
Member Author

@bors r=Amaneiu

@bors
Copy link
Contributor

bors commented Apr 26, 2020

📌 Commit b00afb5 has been approved by Amaneiu

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 26, 2020
@bors
Copy link
Contributor

bors commented Apr 27, 2020

⌛ Testing commit b00afb5 with merge 80ba2ba544868e6ae3dc83dd5c18cb6764c905da...

@bors
Copy link
Contributor

bors commented Apr 27, 2020

💔 Test failed - checks-azure

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 27, 2020
@sfackler
Copy link
Member Author

@bors r=Amaneiu

@bors
Copy link
Contributor

bors commented Apr 27, 2020

📌 Commit c68f23f has been approved by Amaneiu

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 27, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 27, 2020
Rollup of 7 pull requests

Successful merges:

 - rust-lang#67841 (Add Read/Write::can_read/write_vectored)
 - rust-lang#71524 (Minimize parameter of coerce_borrowed_pointer())
 - rust-lang#71558 (Cleanup and document `-Z tls-model` )
 - rust-lang#71578 (linkchecker: fix typo in main.rs)
 - rust-lang#71596 (Fix broken link in `QPath` documentation)
 - rust-lang#71604 (make recursive-zst test unleashed)
 - rust-lang#71605 (No need to whitelist E0750 anymore)

Failed merges:

r? @ghost
@bors bors merged commit c4d9f42 into rust-lang:master Apr 28, 2020
iceiix added a commit to iceiix/fs-web that referenced this pull request Jan 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants