Doodle3D / print3d

The application that runs on a Doodle3D WiFi box that communicates with printers.
www.doodle3d.com
GNU General Public License v2.0
13 stars 4 forks source link

Log rotation #32

Closed peteruithoven closed 8 years ago

peteruithoven commented 8 years ago

Like @mpbomil noticed, currently our print3D logfiles keep growing on the limited RAM space of the WiFi-Box. One solution would be to implement some kind of log rotation. This means older logs are automatically removed.

It would be important to keep the first 100 / 200 lines, since this contains information about the 3D printer and how we've made the connection.

We can implement something ourselves, but we should probably use the regular logrotate utility, see: http://groenholdt.net/Computers/OpenWRT/openwrt-logrotate.html http://www.thegeekstuff.com/2010/07/logrotate-examples/ http://linux.die.net/man/8/logrotate http://manpages.ubuntu.com/manpages/saucy/en/man8/logrotate.8.html

woutgg commented 8 years ago

Enabling logrotate in Openwrt and using it i.c.w. cron looks like a suitable approach. The manual can be found here.

Parameters we should find good values for (including proposals):

Further aspects to consider:

When rotation is in place, there are two further things to implement:

peteruithoven commented 8 years ago

With keeping the first lines you mean keeping the logs related to the initialization of the firmware / print3d?

woutgg commented 8 years ago

Indeed, I've updated the comment.

peteruithoven commented 8 years ago

(It's also relevant for the firmware (wifibox.log), because of the wifi related initialization.)

woutgg commented 8 years ago

Good point.

peteruithoven commented 8 years ago

With the early logrotation changes we did a big print on the Ultimaker2 and I did notice some momentary freezes, this might be caused by the copytruncate trick. These freezes are visible in the prints in the form of blobs: img_20160315_192219

companje commented 8 years ago

Are the blobs in the photo only occurring when logging extensively? Or is also a problem in normal use?

peteruithoven commented 8 years ago

We have not tested this yet without heavy logging.

woutgg commented 8 years ago

I would also suspect the compress option, this can quickly be disabled (it might be wise to also lower the rotate setting to 1 then). In either case, rotating earlier (e.g. at 500k) could reduce the freezing.

woutgg commented 8 years ago

I could not reproduce this. The printer did not stutter visibly or audibly while logrotate was running. Inspecting top during the rotation, I could see gzip running for a few seconds, taking about 80% of CPU, but it did not seem to have any impact on printing.

The stuttering might have had to do with a higher setting of Printer.MAX_LINES_PER_POST in the client.

Closing this for now.

peteruithoven commented 8 years ago

Even though we couldn't reproduce the blobs with a regular MAX_LINES_PER_POST there are still little things to fix for logrotation.

woutgg commented 8 years ago

The important aspects have all been implemented (see merge commit here).

We have decided not to implement log reopening on sighup/sigusr1 in print3d and firmware, assuming the copytruncate option will work well.

jeroensomers commented 8 years ago

I looked at the memory usage by doing "while true; do date; free; sleep 5; done" within the SSH of the WiFi-Box. The free memory goes down for about 3 minutes than log rotation comes in and the free memory goes up again. Most of the time the memory is between 2000 en 3000 (2 MB / 3MB) before it goes up again. This was while printing on the Ultimaker 2.

peteruithoven commented 8 years ago

On the test WiFi-Box I've lowered the logrotate size from 1000k to 500k. Hopefully this will give us a bit more playroom.

woutgg commented 8 years ago

The 3 minute interval however is a lower bound by the cron configuration so perhaps we should also lower that a bit.

peteruithoven commented 8 years ago

@woutgg What do you mean with lower bound?

woutgg commented 8 years ago

It will only run every 3 minutes, so regardless of actual log size, the logs will never be rotated sooner than the next time cron runs logrotate.

peteruithoven commented 8 years ago

Ah, I was convinced it was 3min. In that case, shouldn't we first lower just the interval? Because every rotate costs processing power. I've created a easier to use check that allows sorting:

while true; do echo "$(cat /proc/meminfo | grep MemFree | sed -E 's/^[^0-9]+//') $(date '+%H:%M:%S')";
woutgg commented 8 years ago

Yes, 3 minutes indeed. And I think we can safely lower it. Logrotate will only actually do something when the files are larger than the limit we set so it's rather cheap to run.