Thread: file IO speed over network

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    412
    You could also cache the files locally in memory or on disk. Check the last modified timestamp of the file(s) on the network share at some interval, and if newer update the cache.
    Quote Originally Posted by MK27 View Post
    An megabit is about 1 kilobyte.
    1 MBit is 125 or 128 KByte depending on if you count Kilo as 1000 or 1024
    Last edited by _Mike; 09-02-2011 at 08:40 AM. Reason: misspelled count as could :/

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by _Mike View Post
    1 MBit is 125 or 128 KByte depending on if you could Kilo as 1000 or 1024
    Actually we're both wrong, lol. A megabit (100000 bits) is 12500 bytes, which is 12.2 kB (using a 1024 byte kB).

    Quote Originally Posted by jimblumberg View Post
    Reading a file character by character is slower than reading a large section of the file at a time.
    And that difference will probably be compounded on a network, presuming each read requires some kind of in-protocol packet exchange as overhead, which is going to be a number of bytes.

    Ie, if you read one byte at a time and there are 9 bytes of packet overhead per request, your 100 MBits/sec connection will be 10 Mbits effectively. If you are reading a line at a time, the lines are ~40 bytes, and the overhead is 8 bytes, you will get at most 80% of the network maximum.

    If the files are not huge, stat() them and read the entire thing in at once. Do not use getline().
    Last edited by MK27; 09-02-2011 at 08:24 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    412
    Quote Originally Posted by MK27 View Post
    Actually we're both wrong, lol. A megabit (100000 bits) is 12500 bytes, which is 12.2 kB (using a 1024 byte kB).
    You're missing a 0 in mega And if you use SI-units for mega then you'd have to use it for kilo as well.
    1 Byte is 8 bit.
    Using SI-units for kilo and Mega; 1 Mbit is 1000 kbit. 1000/8 = 125
    Using power-of-two units; 1 Mbit is 1024 kbit. 1024/8 = 128

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by _Mike View Post
    You're missing a 0 in mega
    Yeah, more than once since I did that on a calculator too. I need a less mathematically impaired brain. :/

    Quote Originally Posted by rogster001 View Post
    This is what i was thinking, could you outline any alternative? I can get filesize, read into a buffer, but how to extract the lines after that? as i need to provide a rowcount as part of the reporting
    Stringstreams also have a getline() function. Read into string buffer, apply stringstream, and all your current parsing code can work with that.

    To be honest though, I doubt that will make much difference in terms of getting the network speed to better match the speed of a hard drive -- but it is probably a more polite use of the network & equipment. Imagine if you had three computers reading three different files off the same hard drive at the same time, one line at a time.
    Last edited by MK27; 09-02-2011 at 09:07 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. to receive image file through network port
    By nadeem athani in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-03-2011, 08:50 PM
  2. Speed of pointers vs. speed of arrays/structs
    By Kempelen in forum C Programming
    Replies: 32
    Last Post: 06-27-2008, 10:16 AM
  3. file transfer across network
    By kris.c in forum Networking/Device Communication
    Replies: 6
    Last Post: 06-17-2006, 01:08 PM
  4. Network File Copy in DR DOS
    By daron in forum C Programming
    Replies: 3
    Last Post: 09-30-2005, 01:49 AM
  5. File I/O on Network drive, Quick Question
    By kransk in forum C++ Programming
    Replies: 3
    Last Post: 11-24-2003, 09:17 AM