18.03.2016, 13:47
Getting technical now ![Wink](images/smilies/wink.png)
Theres a pretty tough and stealthy bug in RNPC that randomly crashes NPCs. It seemed like they are connected to the HDD speed, and thanks to a nice user here this is pretty much confirmed now. NPCs crash much more often on slow HDDs, and dont seem to crash at all when using a SSD.
RNPC creates the rec file in the plugin and writes it to the disk, then tells the npcmode script to play it back. Theres a short delay between write and playback due to the NPCs ping, but it seems like this isnt always enough. My theory is that even though fwrite should write instantly, it takes a moment until the whole file is readable (especially on VPS, as they dont have direct hardware access). So the NPC sometimes tries to play not yet existing or incomplete files and crashes.
Ive got several ideas how to fix this problem, but none of them is perfect because it slows RNPC down too much.
1. Add some ms delay to the playback, to give the HDD more time for writing. (this slows down NPC reaction times, and still isnt 100% safe)
2. Add a quick checksum test in the npcmode to ensure the file is complete. (difficult as npcmodes cant access the rec files directly)
3. Create and mount a ramdisk for the rec files and link to it (this would be a great solution, as it would greatly boost the performance, but no idea yet if this is even possible in the plugin)
4. Add a check to the rec file write code to ensure the file is complete before continuing (this could work, but as it runs in the main thread, it could block the server for too long on slow HDDs. Maybe memory-mapped files would work, but dont know if samp can handle them)
Anyone has better ideas? Or is there someone with enough knowledge of server virtualisation to tell if my theory is plausible?
![Wink](images/smilies/wink.png)
Theres a pretty tough and stealthy bug in RNPC that randomly crashes NPCs. It seemed like they are connected to the HDD speed, and thanks to a nice user here this is pretty much confirmed now. NPCs crash much more often on slow HDDs, and dont seem to crash at all when using a SSD.
RNPC creates the rec file in the plugin and writes it to the disk, then tells the npcmode script to play it back. Theres a short delay between write and playback due to the NPCs ping, but it seems like this isnt always enough. My theory is that even though fwrite should write instantly, it takes a moment until the whole file is readable (especially on VPS, as they dont have direct hardware access). So the NPC sometimes tries to play not yet existing or incomplete files and crashes.
Ive got several ideas how to fix this problem, but none of them is perfect because it slows RNPC down too much.
1. Add some ms delay to the playback, to give the HDD more time for writing. (this slows down NPC reaction times, and still isnt 100% safe)
2. Add a quick checksum test in the npcmode to ensure the file is complete. (difficult as npcmodes cant access the rec files directly)
3. Create and mount a ramdisk for the rec files and link to it (this would be a great solution, as it would greatly boost the performance, but no idea yet if this is even possible in the plugin)
4. Add a check to the rec file write code to ensure the file is complete before continuing (this could work, but as it runs in the main thread, it could block the server for too long on slow HDDs. Maybe memory-mapped files would work, but dont know if samp can handle them)
Anyone has better ideas? Or is there someone with enough knowledge of server virtualisation to tell if my theory is plausible?