Comments (3)
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:
- Implement some
MVar
-based blocking whenever writing to the FD, which will likely kill performance - Have a dedicated worker thread which writes chunks to the FD
- 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.
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.
I would close this issue thanks to #103. Please reopen if necessary.
from logger.
Related Issues (20)
- Log rotation by day (00:00:00 to 23:59:59.999) HOT 1
- wai-logger 2.3.3 build failure with fast-logger < 2.4.12 HOT 1
- update fast-logger on github to reflect changes on hackage HOT 2
- ToLogStr instances for Int and Word HOT 3
- Rotate file will loss logs and throw IOException HOT 6
- Build failure with base-4.5 HOT 3
- wai-logger as middleware - openFile: Resource busy (file is locked) HOT 1
- Consider exporting LogStr HOT 1
- syslog support? HOT 1
- Update wai-logger cabal metadata on hackage HOT 1
- ToLogStr instance for ShortByteString
- fast-logger: Breaking API change in minor version bump HOT 4
- Build failures in wai-logger-2.1.0 to 2.3.5 due to missing bounds on fast-logger
- How to use TimedFastLogger with structured logging?
- Check-then-act race condition for short log entries in concurrent logging, results in entries being not in order HOT 3
- fast-logger fails to build with directory >=1.3.8
- `rmLoggerSet` does not flush when `SingleLogger` is in use HOT 4
- SingleLogger misses and repeats log messages HOT 3
- Fastlogger OOM's when setting log_backup_number to maxBound on logfile rotation HOT 1
- Flushing a single stdout logger doesn't seem to flush stdout HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from logger.