Giter Club home page Giter Club logo

Comments (3)

snoyberg avatar snoyberg commented on August 11, 2024

Making this (obviously terribly inefficient) replacement seems to fix the problem:

toBufIOWith :: Buffer -> BufSize -> (Buffer -> Int -> IO ()) -> Builder -> IO ()
toBufIOWith buf !size io builder =
    let (PS fptr off siz) = L.toStrict $ toLazyByteString builder
     in withForeignPtr fptr $ \ptr -> io (ptr `plusPtr` off) siz

The proper way to do this would be, when nlen is greater than the buffer size, allocate a new buffer of the right size and pass it in.

However, I think we're still left open for an interleaved output race condition. Specifically, if the write system call doesn't write all bytes, another thread could take a stab at sending some bytes before our buffer is emptied. The three solutions I can think of for this are:

  1. Implement some MVar-based blocking whenever writing to the FD, which will likely kill performance
  2. Have a dedicated worker thread which writes chunks to the FD
  3. Perhaps there's some way we can use atomicModifyIORef' to let multiple threads all put data into a single ref, but I haven't figured out the right mechanisms to make sure that we don't get interleaved I/O. Perhaps some kind of tricks like we use in auto-update could be employed.

from logger.

lehins avatar lehins commented on August 11, 2024

I was curious about how solving this issue outside fast-logger with STM and MVar would work, here is some benchmarks:
https://rawgit.com/lehins/practice/master/haskell/fast-logger/results.html
Code is here:
https://github.com/lehins/practice/blob/master/haskell/fast-logger/how-fast-logger.hs
It seems that for entries larger than the buffer size and with many threads STM approach does outperform even native (buggy) log writing.
Thought it might be useful here.

from logger.

kazu-yamamoto avatar kazu-yamamoto commented on August 11, 2024

I would close this issue thanks to #103. Please reopen if necessary.

from logger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.