Project

General

Profile

Actions

Feature #9323

closed

IO#writev

Added by Glass_saga (Masaki Matsushita) almost 11 years ago. Updated almost 7 years ago.

Status:
Closed
Target version:
[ruby-core:59408]

Description

I propose addition of IO#writev.
It enables gather output from multiple buffers.
If writev(2) is not available, IO#writev uses Array#join to emulate atomic write.


Files

patch.diff (7.83 KB) patch.diff Glass_saga (Masaki Matsushita), 12/30/2013 10:08 PM
patch.diff (6.28 KB) patch.diff Glass_saga (Masaki Matsushita), 06/27/2017 05:05 AM
patch.diff (6.79 KB) patch.diff IO#write accepts multiple arguments Glass_saga (Masaki Matsushita), 10/21/2017 12:20 PM

Related issues 2 (0 open2 closed)

Related to Ruby master - Feature #9420: warn and puts should be atomicClosedGlass_saga (Masaki Matsushita)Actions
Related to Ruby master - Feature #14042: IO#puts: use writev if availableClosedActions

Updated by normalperson (Eric Wong) over 10 years ago

Unless we have use for it, I don't think rb_io_writev should be in
the C API, and even less reason for it to be public for extensions
in ruby/intern.h

Also, it'd probably be good to dedup the fptr->wbuf initialization
code in io_binwrite*.

Otherwise, I think this is fine.

Updated by ioquatix (Samuel Williams) over 7 years ago

I think this is a great idea. It avoids a ton of string issues - e.g. concatenating strings in Ruby before writing them out. It would be great if #write could take an array, and if possible, call writev.

Actions #4

Updated by Glass_saga (Masaki Matsushita) over 7 years ago

  • Target version changed from 2.2.0 to 2.5

Updated by Glass_saga (Masaki Matsushita) over 7 years ago

It would be great if #write could take an array, and if possible, call writev.

That's would be nice.

File.open("test", "w") do |f|
  f.write("foo", "bar", "baz") # use writev(2) if possible
end

Updated by akr (Akira Tanaka) about 7 years ago

  • Status changed from Open to Feedback

Is there benchmark?

What the situation that writev is actually fast?

Updated by Glass_saga (Masaki Matsushita) about 7 years ago

The main purpose of IO#writev is to make a chance for users to write multiple buffers atomically, not to improve performance.

Updated by normalperson (Eric Wong) about 7 years ago

wrote:

The main purpose of IO#writev is to make a chance for users to
write multiple buffers atomically, not to improve performance.

IO#write on Array#join result is atomic, too; but Array#join can
result in too large buffers and excessive memory use.

I wrote benchmarks for shards io-extra project on Rubyforge
years ago, but I guess that email is no longer available publically.
I've quoted and reposted the test to spew:

https://80x24.org/spew/20170926005509.GA22313@starla/raw

Updated by matz (Yukihiro Matsumoto) almost 7 years ago

I vote for making IO#write take multiple arguments, probably using writev(2) inside.

Matz

Updated by Glass_saga (Masaki Matsushita) almost 7 years ago

  • File patch.diff patch.diff added
  • Status changed from Feedback to Assigned
  • Assignee set to Glass_saga (Masaki Matsushita)

This patch makes IO#write accept multiple arguments.

Actions #11

Updated by nobu (Nobuyoshi Nakada) almost 7 years ago

  • Status changed from Assigned to Closed

Applied in changeset trunk|r60351.


io.c: fix local variables

  • io.c (io_writev): fix local variable declarations, when
    writev(2) is not available. [Feature #9323]
Actions #12

Updated by shyouhei (Shyouhei Urabe) almost 7 years ago

Actions #13

Updated by shyouhei (Shyouhei Urabe) almost 7 years ago

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0