i writing program in c++ , wonder if can me situation explained here.
suppose, have log file of size 30mb, have copied last 2mb of file buffer within program.
i delete file (or clear contents) , write 2mb file.
everything works fine till here. but, concern read file (the last 2mb) , clear file (the 30mb file) , write last 2mb. of time needed if in scenario copying last 300mb of file 1gb file.
does have idea of making process simpler?
when having large log file following reasons should , considered.
disk space: log files uncompressed plain text , consume large amounts of space. typical compression reduce file size 10:1. file cannot compressed when in use (locked). log file must rotated out of use.
system resources: opening , closing file regularly consume lots of system resources , reduce performance of server.
file size: small files easier backup , restore in case of failure.
i not want copy, clear , re-write last specific lines file. simpler process.... :-)
edit: not making inhouse process support log rotation. logrotate tool.
i suggest different approach.
- create new temporary file
- copy required data original file temporary file
- close both files
- delete original file
- rename temp file same name original file
to improve performance of copy, can copy data in chunks, can play around chunk size find optimal value.
Comments
Post a Comment