-1

Does anybody see the difference between these two lines?

1) ret = write( fd_out, local_bugger, bytes_to_move);

2) nwritten = write (fd, buf + total_written, size - total_written);

Obviously, not the naming conventions.

Specifically, one is writing over the network 4x faster than the other.

Looking for logic , flags, etc

THANKS

c card
  • 213
  • 3
  • 10
  • 1
    Totally guessing, but one looks likes like it writes in one big chunk, whilst the other looks like it's probably part of a loop writing smaller chunks. That would explain possible performance differences though. Can you include some more context, or better yet make a [SSCCE](http://sscce.org/)? – Flexo Sep 21 '11 at 20:56
  • What about underlying hardware? Both writing to the same disk? Is one writing over the network? Can we assume you've accounted for the size of the data being written? – Marvo Sep 21 '11 at 20:57
  • OT, but I think you meant that second parameter on the first line to be `local_buffer`. – T.E.D. Sep 21 '11 at 21:07
  • Vote to close: Without any context, this is impossible to answer. – Oliver Charlesworth Sep 22 '11 at 00:44

2 Answers2

6

what are the values/types of all those? Right now this question can't be answered... does option 2) end up writing 4x as much data? What are the flag options on the fopens for the two handle? etc...

Right now I'll guess that it's because mars is ascendent in jupiter and the moon is gibbous waxing, causing the higgs bosons to mess with the quarks in your ethernet cable.

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • 2
    *"jupiter and the moon is gibbous waxing, causing the higgs bosons to mess with the quarks"* - that's quite the psychic debugger you've got there. What version are you using? – Flexo Sep 21 '11 at 20:58
  • Right now all you'll get ARE bs answers, because you've walked into a a garage and told the mechanic: "I've got 2 cars, one drives faster than the other. Why? The steering wheel on one is purple" – Marc B Sep 21 '11 at 21:02
  • yes it is option 2. for now, this is the context. – c card Sep 21 '11 at 21:03
  • 4x data will be 4x slower because there's 4x more of it. What's the question then? – Flexo Sep 21 '11 at 21:04
  • "option 2", so it's car parked on the left side of your driveway? wow... useful... – Marc B Sep 21 '11 at 21:04
  • Perhaps it is because `write` got a bit sore after having that second parameter on the first line passed into it. – T.E.D. Sep 21 '11 at 21:11
0

There could be two things at play here:

  1. The size of the chunks you're writing. Small chunks incur more overhead. But that's unlikely to cause a big difference unless you're writing less than 16 bytes or so.
  2. The details of the file descriptor you're writing to. How much buffering does it have? Is it going through a filesystem (NFS or CIFS)? Is it even going out over the same network?

In short, as Marc B answered: not enough information.

Arnout
  • 2,927
  • 16
  • 24
  • perhaps the issues is with the fcntl flags set on the file descriptor. What would be the right fcntl flags when reading from a disk and writing to a file over the network for best speed? – c card Sep 21 '11 at 21:17