SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 28/09/2011, 10:05 PM   #1
JernejL
Beta Tester
 
JernejL's Avatar
 
Join Date: Jan 2006
Location: Slovenia
Posts: 613
Reputation: 413
Spray [REL] Threaded Fread & Fwrite plugin

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:

Code:
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.
__________________
Please, do no message me anymore, i'm no longer part of sa-mp scene.

I will not reply to private messages.
JernejL is offline   Reply With Quote
Old 28/09/2011, 10:07 PM   #2
Scott
Big Clucker
 
Join Date: Aug 2010
Location: Santa Barbara, CA
Posts: 122
Reputation: 133
Default Re: [REL] Threaded Fread & Fwrite plugin

Great job!
Scott is offline   Reply With Quote
Old 28/09/2011, 10:13 PM   #3
Phanto90
Huge Clucker
 
Phanto90's Avatar
 
Join Date: Mar 2011
Location: Milan, Italy
Posts: 340
Reputation: 31
Default Re: [REL] Threaded Fread & Fwrite plugin

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


Latest Releases
FilterscriptsIncludesMaps
PRaceSystem v1.3 PBlock v1.1Electronic Shop
PVotekick v1.1PInventory v1.1
________________________
I don't script for money, stop asking for it.

Phanto90 is offline   Reply With Quote
Old 28/09/2011, 10:15 PM   #4
CJ101
High-roller
 
CJ101's Avatar
 
Join Date: Jan 2008
Location: RevolutionX
Posts: 1,904
Reputation: 162
Default Re: [REL] Threaded Fread & Fwrite plugin

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

OT: does it feature turtles?
__________________
[/url]
CJ101 is offline   Reply With Quote
Old 28/09/2011, 10:18 PM   #5
JernejL
Beta Tester
 
JernejL's Avatar
 
Join Date: Jan 2006
Location: Slovenia
Posts: 613
Reputation: 413
Default Re: [REL] Threaded Fread & Fwrite plugin

Turtle plugin is still work in progress.
__________________
Please, do no message me anymore, i'm no longer part of sa-mp scene.

I will not reply to private messages.
JernejL is offline   Reply With Quote
Old 28/09/2011, 10:22 PM   #6
GhoulSlayeR
Little Clucker
 
GhoulSlayeR's Avatar
 
Join Date: Dec 2009
Posts: 47
Reputation: 40
Default Re: [REL] Threaded Fread & Fwrite plugin

Good work, i'll run the usual tests later.
__________________

Former Official Developer for Next Generation Gaming, LLC
GhoulSlayeR is offline   Reply With Quote
Old 28/09/2011, 11:11 PM   #7
Babul
High-roller
 
Babul's Avatar
 
Join Date: Sep 2009
Location: in a cement block
Posts: 1,893
Reputation: 251
Default Re: [REL] Threaded Fread & Fwrite plugin

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 >-<
__________________
FireWorks

new sscanf2 custom specifiers available for Download, read the Release Topic

Last edited by Babul; 29/09/2011 at 12:46 AM.
Babul is offline   Reply With Quote
Old 29/09/2011, 06:33 AM   #8
olaf137
Big Clucker
 
Join Date: Sep 2009
Posts: 65
Reputation: 3
Default Re: [REL] Threaded Fread & Fwrite plugin

You could use sscanf to unformat the large string.
olaf137 is offline   Reply With Quote
Old 29/09/2011, 06:39 AM   #9
HyperZ
High-roller
 
HyperZ's Avatar
 
Join Date: Aug 2009
Posts: 1,389
Reputation: 66
Default Re: [REL] Threaded Fread & Fwrite plugin

Nice work.
__________________
HyperZ is offline   Reply With Quote
Old 29/09/2011, 07:16 AM   #10
JernejL
Beta Tester
 
JernejL's Avatar
 
Join Date: Jan 2006
Location: Slovenia
Posts: 613
Reputation: 413
Default Re: [REL] Threaded Fread & Fwrite plugin

Just a heads-up, there's a memory leak in threaded read function - i will fix this as soon as i get home from work.

Babul: some string parsing could do what you want, i could add you another callback, which would call it per-line if you wish.
__________________
Please, do no message me anymore, i'm no longer part of sa-mp scene.

I will not reply to private messages.
JernejL is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SendClientMessage fails to work in some threaded queries. Why? _Outbreak_ Scripting Help 3 30/09/2011 11:44 AM
Threaded queries armyoftwo Help Archive 0 11/12/2010 01:49 PM
Help with fread jonrb Help Archive 2 06/12/2009 03:54 PM


All times are GMT. The time now is 02:33 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.