4

Does it slow down a website if your webserver (in my case, nginx) is writing to an access log?

I'm mostly wondering if it's noticeable.

Plus, what's the point of knowing the user agents / ips that have visited?

Matthew
  • 1,859
  • 4
  • 22
  • 32

2 Answers2

7

I don't believe you will notice any hit in performance. Log writes will likely be buffered and then flushed out to disk. So unless you have high disk load you will be fine. If you do have high disk load than you probably want more memory (if this is only a webserver) so web data is served from a memory cache.

Nginx is programmed with an event driven methodology so log writes shouldn't block the serving of pages. I imagine threaded / forking web servers probably use a different thread or process for this as well.

You could also send logs to an external host with syslog (or perhaps even using a Nginx directive).

User-Agents help you know where the traffic comes from and the browser. Good crawlers will set a UA like "Googlebot" and browsers should be specified in the UA. IPs also help identify traffic sources. You will want this information if you ever want some analytics from the logs with something like awstats.

Kyle Brandt
  • 83,619
  • 74
  • 305
  • 448
  • Log writes are indeed buffered by default at 64K. NGINX writes each time it has more than 64KB of log data buffered though you can set this value `access_log buffer=128k`. – Marc May 20 '21 at 06:32
  • @Marc, I don't think this is entirely accurate, I can do a `tail -f access_log` and see it updating in real-time. – CaptainCodeman May 26 '22 at 15:30
4

Compared to the resources necessary to process a request, the writing of one line of log is usually not a big deal and the file is opened once (Unless you are the victim of some DOS attacks, where the log - written to the disk after a number of accesses - will keep your machine pretty busy).

Regarding the logs, I keep my Nginx outputs to make some statistics (where are the accesses, from which country, which browser etc...).

If you don't need them, and/or worry about the disk space they take, check the logrotate configuration for nginx (should be in /etc/logrotate.d, file nginx). The Ubuntu default is rotate for 52 weeks, meaning that logs older than a year are deleted.

Déjà vu
  • 5,546
  • 9
  • 36
  • 55