开发者

Logging to innoDB table or local file, which one is faster?

I need to implement a simple logging mechanism for my web application. I have two options available, one is to put the logging records into a local file, e.g. somewhere like /tmp/file.log, the other way is to use an InnoDB table(located in a busy database), which is write only and has no read operation involved. The table is straight forward, with two columns one is the primary id column which is auto incremented, the other is the logging text of type text(1024). The logging will be called 10 times per second, means it does 10 writes per second. Currently I do not have access to the production server to actually benchmark these two different ways in the real environment. Which one would be faster, generally speaking, and why?

Personally I would perfer to go with the InnoDB way, coz it simplifies my code a little bit. And I believe there is a reaso开发者_运维知识库n why most web applications encourage to turn off runtime file logging in production env. However the innoDB table does locate in a busy database, will that degrade the logging performance and make it slower than file logging?

Thanks.


The database can buffer things and thereby optimise disk access (which is horribly slow compared to memory) which the file logging option won't do, making it quite a bit faster. I mean, it shouldn't be slower, worst-case scenario is it behaves just like file logging.

How much faster it is depends on way too many variables (e.g. if it has a memory limit it might not be able to hold lots of data in memory so it will save to disk often, which depends on the OS, the database implementation, the table engine, the load on the server, other things the database is doing, etc.), although benchmarking over a day or so (which should represent different loads etc.) should give you some idea of how much faster.

Google buffer cache for a peek into the world of database buffering (which is more often referenced for disk reads, although its true for disk writes as well)


The DB solutions add a lot of complexity:

  • Client-Server communication
  • SQL Parser
  • Query Engine
  • ...

The file solution is direct, and most operating systems will give you some kind of write-caching for free on non-removable devices.

So, go for the file. It won't be slower, and it's a lot simpler!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜