non-blocking writing to file ...

Ask a Question related to PERL Modules, Design and Development.

  1. #1

    Default Re: non-blocking writing to file ...

    Dieter D'Hoker wrote:
    >
    > I write a gameserver written in perl ,
    > so pign is very important ,
    What is "pign" ?
    > every 15 minutes it writes winlist , configuration ,s tatistics ,
    > profiles , ... to different files ...
    > It takes some time to do so , so if there was a game goign on at that
    > moment it will "block" for a some time .
    > (not that much the files aren't that big but still ...)
    You may be able to cut down the speed of this by opening the filehandles
    once when your program starts, and never closing them. After each time
    that you write all your stuff to a particular file, seek() that handle
    back to the beginning.
    > Now I first tried it to make it non-bloking by forking my server ,
    > and writing the file in my child ,
    This will only improve your program's speed if you do it on unix, where
    real fork()ing exists -- if you're on windows, fork() is emulated using
    something called "ithreads." Although ithreads provides much of the
    functionality of fork, the startup time is quite big.

    Oh, and it will only help the program's speed if the data segment of a
    process's memory is copied using copy-on-write.
    > but that even results in even more time lost I noticed ,
    > I guess because it has to copy the entire server into memory ,
    > and the server does take quite an amount of ram ...
    >
    > next option would be using threading ,
    > but becaus emy shell doesn't support threading this is not an option
    > ...
    If this were C, then threads would be your best bet.

    Or possibly posix AIO, or some other asynchronous IO module.
    > maybe there is a module that can do this ?
    To magically speed up your program? Not likely.
    > or some other method ?
    Besides keeping the filehandles open, you might consider writing the
    data only at times when a delay won't be noticable.

    Also, writing a little data at a time might help -- just write the
    winlist, and then later on, just write the configuration, then later on,
    just write the statistics, etc.
    > I thought of preforkign a child , running a server on the child ,
    > where the parent can conenct to from time to time passing thourgh the
    > files , and the the child saves them , but that's kinda complicated do
    > do I guess
    > ...
    Not just complicated, but (even ignoring the overhead of preforking and
    connecting), you still will need to transfer the data from the parent to
    the child!
    > any ideas ?
    > or examples of code ?
    --
    $a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
    );{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
    ]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
    Benjamin Goldberg Guest

  2. Similar Questions and Discussions

    1. Writing a text file to the file system
      Using Visual Studio C# When I ran the following code: System.IO; private void Button1_Click(object sender, System.EventArgs e) {...
    2. Setting the file permissions of a file I'm writing to
      Is it possible to specify the permissions of a file I create when I: open ("FOO", "> ./bar") or die ("Could not create file"); Thanks in...
    3. Will Thread blocking in read() leads to process blocking?
      Hi! Yes, the outcome depends on the threads implementation. However, it is incorrect to believe that a POSIX conformant implementation won't...
    4. File Access error - writing to .txt file
      Normally web sites run under the ASPNET user account. It appears that this account does not have write privileges to the file path you've...
    5. A failure occurred writing to the resources file. Access is denied. -- RESX file is locked? -- WHY?
      Hi. This is an error that comes up fairly regularly when trying to run the "Rebuild All" command in a Solution that contains more than one...
  3. #2

    Default Re: non-blocking writing to file ...

    Dieter D'Hoker wrote:
    >
    > I write a gameserver written in perl ,
    > so pign is very important ,
    What is "pign" ?
    > every 15 minutes it writes winlist , configuration ,s tatistics ,
    > profiles , ... to different files ...
    > It takes some time to do so , so if there was a game goign on at that
    > moment it will "block" for a some time .
    > (not that much the files aren't that big but still ...)
    You may be able to cut down the speed of this by opening the filehandles
    once when your program starts, and never closing them. After each time
    that you write all your stuff to a particular file, seek() that handle
    back to the beginning.
    > Now I first tried it to make it non-bloking by forking my server ,
    > and writing the file in my child ,
    This will only improve your program's speed if you do it on unix, where
    real fork()ing exists -- if you're on windows, fork() is emulated using
    something called "ithreads." Although ithreads provides much of the
    functionality of fork, the startup time is quite big.

    Oh, and it will only help the program's speed if the data segment of a
    process's memory is copied using copy-on-write.
    > but that even results in even more time lost I noticed ,
    > I guess because it has to copy the entire server into memory ,
    > and the server does take quite an amount of ram ...
    >
    > next option would be using threading ,
    > but becaus emy shell doesn't support threading this is not an option
    > ...
    If this were C, then threads would be your best bet.

    Or possibly posix AIO, or some other asynchronous IO module.
    > maybe there is a module that can do this ?
    To magically speed up your program? Not likely.
    > or some other method ?
    Besides keeping the filehandles open, you might consider writing the
    data only at times when a delay won't be noticable.

    Also, writing a little data at a time might help -- just write the
    winlist, and then later on, just write the configuration, then later on,
    just write the statistics, etc.
    > I thought of preforkign a child , running a server on the child ,
    > where the parent can conenct to from time to time passing thourgh the
    > files , and the the child saves them , but that's kinda complicated do
    > do I guess
    > ...
    Not just complicated, but (even ignoring the overhead of preforking and
    connecting), you still will need to transfer the data from the parent to
    the child!
    > any ideas ?
    > or examples of code ?
    --
    $a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
    );{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
    ]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
    Benjamin Goldberg Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139