[Plugin] [REL] Threaded Fread & Fwrite plugin
#1

This is a THREADED Fread / Fwrite plugin.

When you use fread / fwrite in pawn directly, if a file is being read by another external program, or hdd writing is slow or file IO is under a strain, you will end up losing some miliseconds in server sync due to file system locking to accomodate the underlying safety mechanisms in order to ensure a stable file transaction.

This can become painfully obvious if you still use text files to store accounts. I know that on a few very popular servers this problem can take whole seconds to finish - imagine a random up to 1 second ini file reading lag on the server whenever a player joins - same can happen during leaving & writing data to account.

This plugin allows you to write data to file without this waiting delay, so you can "shove" out large amouts of data without any problems.
Reading is also done without any locking - the thread will load the data you desire and pass it to your callback.

The main purpose of the plugin is basically.. outputing a lot of data to text files without lagging the script.

Natives:

pawn Код:
native ThreadW(file[], text[]);
native ThreadR(file[], callback[], beginoffset = 0, extraid = -1);
Download .inc, win32 dll and linux 32bit .so:
http://www.mathpudding.com/temp/rwthread.rar

Download source code:
http://www.mathpudding.com/temp/rwthread_src.rar

Example usage:

Quote:

forward readwholetext(texts[], extraid);
public readwholetext(texts[], extraid) {

printf("received from thread: \"%s\" extraid: %d.", texts, extraid);

}

ThreadW("scriptfiles/test.txt", "TEXT MEEEEEE\n");
ThreadW("scriptfiles/test.txt", "LINE 2\n");
ThreadW("scriptfiles/test.txt", "MOAR LINES\n");
ThreadR("scriptfiles/test.txt", "readwholetext", 5); // read everything in this file starting at 5 bytes offset.

NOTE that this is still a very untested plugin, if you intend to use it make sure you understand what it is for and that it might screw things up for you - i cannot and will not take any responsibility for lost data because of this plugin.

Additionally - thanks to BlueG for his work on threads in his mysql plugin. This plugin is based on his work.
Reply
#2

Great job!
Reply
#3

Nice! I've not tested it but if it works good as threaded queries then good job.
Reply
#4

Awesome that we finally have something like this. Me likes.

OT: does it feature turtles?
Reply
#5

Turtle plugin is still work in progress.
Reply
#6

Good work, i'll run the usual tests later.
Reply
#7

oh, thats exactly what i need. i AM using the native functions to store data - i will definetly give it a intensive test-drive at the weekend. thank you!
question: is there a chance that you add a function to get all entries of a directory? it would come in handy for getting all race files existing. the way i do it by storing all saved races in another file, can be a pain...

edit: i encountered some problems at scaninng files like a "fake directory" with unknown size. some files are >2000 chars in size, f.ex using 50 race names. i cant figure out how to parse them properly coz all data gets put into a huge string instead of the chance to fread 50 lines >-<
Reply
#8

You could use sscanf to unformat the large string.
Reply
#9

Nice work.
Reply
#10

Quote:
Originally Posted by Babul
Посмотреть сообщение
question: is there a chance that you add a function to get all entries of a directory? it would come in handy for getting all race files existing. the way i do it by storing all saved races in another file, can be a pain...
I'm sorry for being that kind of bastard, but I have to say that this is scriptable and I already made it

If you're interested, contact me.
Reply
#11

This looks nice
Reply
#12

This is awesome now server will be not lag when i save a file
Reply
#13

Nice!
Reply
#14

Thanks for this plugin, alot of stuffs are beeing writed to log files in my server and this really was a good upgrade from fwrite
Reply
#15

Where Threaded for Fwrite?
Code:
native ThreadW(file[], text[]);
native ThreadR(file[], callback[], beginoffset = 0, extraid = -1);
example ThreadW(file[], text[], callback[], extraid = -1);
Reply
#16

it is epic,
Love ya mr. turtle
Reply
#17

Link is down, please update the link.
Reply
#18

update download link pls.
Reply
#19

I dug up my old HDD and found only Win32 version from 29.09.2011.
Reply
#20

Quote:
Originally Posted by QuaTTrO
View Post
I dug up my old HDD and found only Win32 version from 29.09.2011.
You have the plugin but in version .so?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)