Salam_Dadash Posted December 8, 2020 Share Posted December 8, 2020 Hi everyone. I Want write a log system for my server but I Don't have any ideas to make it! What method is better than another methods to write log system ? XML or MySQL ? Anybody can help me? please explain the details and problems of these two to me if I Use dbQuery too many times, can Be Lag or other problems ? Link to comment
Addlibs Posted December 8, 2020 Share Posted December 8, 2020 (edited) I'd avoid using files, they're more of a hassle to work with, you have to save manually, etc. They're useful for configurations and whatnot. Databases are better, and you can index, sort and filter the logs much easier with SQL. dbQuery, and db* functions in general, don't cause server lag, only dbPoll if you use -1 for timeout as it awaits results of the query, but for adding entries into the logs you don't need to poll at all; poll is only needed to retrieve the logs, and async callback can let you know when the result is ready without freezing the server. Edited December 8, 2020 by Addlibs 1 Link to comment
Salam_Dadash Posted December 9, 2020 Author Share Posted December 9, 2020 10 hours ago, Addlibs said: I'd avoid using files, they're more of a hassle to work with, you have to save manually, etc. They're useful for configurations and whatnot. Databases are better, and you can index, sort and filter the logs much easier with SQL. dbQuery, and db* functions in general, don't cause server lag, only dbPoll if you use -1 for timeout as it awaits results of the query, but for adding entries into the logs you don't need to poll at all; poll is only needed to retrieve the logs, and async callback can let you know when the result is ready without freezing the server. Uh , thank you so much Link to comment
Forthwind Posted December 11, 2020 Share Posted December 11, 2020 (edited) On 08/12/2020 at 17:53, Addlibs said: I'd avoid using files, they're more of a hassle to work with, you have to save manually, etc. They're useful for configurations and whatnot. Databases are better, and you can index, sort and filter the logs much easier with SQL. dbQuery, and db* functions in general, don't cause server lag, only dbPoll if you use -1 for timeout as it awaits results of the query, but for adding entries into the logs you don't need to poll at all; poll is only needed to retrieve the logs, and async callback can let you know when the result is ready without freezing the server. Would you say using files is slower than db or is there more or less no speed/performance difference? Edited December 11, 2020 by Forthwind Link to comment
Moderators IIYAMA Posted December 11, 2020 Moderators Share Posted December 11, 2020 1 hour ago, Forthwind said: Would you say using files is slower than db or is there more or less no speed/performance difference? A database would use more CPU than just a plain file. When using a timeout (as Addlibs said), you can separate the database thread from the MTA thread. When having multiple CPU cores in your VPS server. Your CPU can automatic assign both threads to different cores, which leads to a very low impact on the performance. As for the file, MTA doesn't write directly to the hard drive, there is a buffer in between. Read more about flushing the buffer here. (Note: You shouldn't flush log files without reason) There is no big penalty here either. Very simple writing to a log file: local hFile = fileOpen("test.txt") -- attempt to open the file (read and write mode) if hFile then -- check if it was successfully opened fileSetPos( hFile, fileGetSize( hFile ) ) -- move position to the end of the file fileWrite(hFile, "hello" ) -- append data fileFlush(hFile) -- Flush the appended data into the file. fileClose(hFile) -- close the file once we're done with it else outputConsole("Unable to open test.txt") end -- https://wiki.multitheftauto.com/wiki/FileOpen And the downside of plain file has explained Addlibs already: Accessibility. XML? That is not a good idea for infinity data. XML uses a node system, each node representing a data-location in the XML tree, when you load the file, you load also all the nodes in to the memory. Loading the file should take longer based on the amount of nodes. 2 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now