scala - Multiple Actors that writes to the same file + rotate -


i have written simple webserver in scala (based on actors). purpose of log events our frontend server (such if user clicks button or page loaded). file need rotated every 64-100mb or , send s3 later analysis hadoop. amount of traffic 50-100 calls/s

some questions pops mind:

  1. how make sure actors can write 1 file in thread safe way?
  2. what best way rotate file after x amount of mb. should in code or filesystem (if filesystem, how verify file isn't in middle of write or buffer flushed)

one simple method have single file writer actor serialized writes disk. have multiple request handler actors fed updates processed logging events frontend server. you'd concurrency in request handling while still serializing writes log file. having more single actor open possibility of concurrent writes, @ best corrupt log file. basically, if want thread-safe in actor model, should executed on single actor. unfortunately, task inherently serial @ point write disk. could more involved merge log files coming multiple actors @ rotation time seems overkill. unless you're generating 64-100mb in second or two, i'd surprised if threads doing i/o bought anything.

assuming single writing actor, it's pretty trivial calculate amount has been written since last rotation , don't think tracking in actor's internal state versus polling filesystem make difference 1 way or other.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -