Log System efficiency
#1

Open, write, close, open, write, close, again and again and again everytime anyone writes in the chat/does a command/buys something or what so ever - that's super slow and will probably decrease the server performence if many players are logged in. The print and printf natives are probably faster but it is impossible to log an entire server into one file. So what are the solutions? Is it better to fopen() a file, log whatever you want and fclose() it when the server shuts down? Also, I don't think at all that it is worthy to consume TONS of memory on strings and just write the strings to files when the server shuts down.
I'll be glad to hear your opinions on what is the most efficient way to make a log system- especially if you want separate logs for each and every player.
Reply
#2

i suggest you to keep the file open while the server is running. if you restart/exit/crash the server, the file will remain intact.
to estimate the CPU usage, i suggest you to use the Profiler Plugin by Incognito
https://sampforum.blast.hk/showthread.php?tid=271129
if your players arent spamming >50 lines per second, then dont hesitate to log each line. just script it, and see how many microseconds each log needs...
Код:
Function  	Calls  	Time per call, µs  	Overall time, µs  	Overall time, %
fread  		39285  	4  			159927  		0.18
format  	502542  3  			1337524  		1.54
fclose  	320  	12  			3883  			0.00
a quick estimation of file read processes. takes 4 microseconds each. assuming that youre not processing the strings anymore before logging, i guess 1 chatline will take like 80-200 µs to process (fopen, format string, fwrite, fclose).
if you keep it open, then you save "only" 2 processes each. wont matter if you ask me hehe
Reply
#3

Let's say I want to continously write into players individual logs and a few global ones, then I guess it would be really bad to have so many files always opened, right?
How about PVaring (to keep the AMX size normal) logs up until it reaches for example 1000 characters and then reset the variable and write to the file?

Cool, I've noticed you added that list thing, that's interesting, where can I get speed estimations for file opening and file writing?
Reply
#4

afaik, the profiler plugin detects (estimates) the speed of callbacks/functions. so if you create a simple one like
Код:
public SavePlayerLog(playerid,logtext[]){
//your fopen, fwrite, fclose etc
}
then, in the OnPlayerText, format the player chat-string and use it as parameter in the SavePlayerLog(playerid,new formatted string?) callback.
a good idea is to add some spamming npcs when its working for you (to estimate how much CPU it takes at all im comparison to the other stuff being profiled).
oh, if you want to log into 500 playerfiles, then i think its a bad idea to keep them all opened.
take 500 players chat logged into one file: thats 500 fwrite(). if you write them additionally to a single "per player" chatlog, then it will use 2x more CPU for the file writing, but also 500 more fopen, fclose aswell. this wont take too much time. since a simple function like the fopen() needs like 1 µs only...
multiply that 1 by 2 (open and close playerfile are 2 operations additionally) plus 500 more for writing each chatline twice (1 to global, 1 for player file)
so, instead writing 500 chatlines to ONE file could need like 100 ms, the per-player solution could take 3x the time. nothing to worry about imo
Reply
#5

My idea was to log their entire chats just like SAMP does (SAMP\chatlog.txt).
So the ideal way to do this is by opening writing and closing each time, I guess. Would you do this or in your opinion that's too much?
Reply
#6

it wont harm gameplay to log everything. iam saving playerdata each second, and each set contains like 200 lines written to the file. even at saving 20 player files at the same time didnt lag for me. hence its just a few bytes getting handled. if you use the native functions like fwrite, iam sure you do
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)