Another way of doing multi-threading - HTTP
#1

Hi.

I've read Mauzen's thread about the multi-threaded PAWN using samp-npc.exe, but all we can do is limited to actions about players.

If we associate this to the HTTP system, some tasks which looks heavy but simple (finding something in a huge array for example) can be done in PHP and then, using echo as a "return", we can determine if the task was done correctly.

I used this system in my anti cheat.
I have a big list of VPN IPs, all are in a PHP array, then, in PAWN, to check whether the IP is a VPN or not, I do like this (under OnIncomingConnection) :

pawn Code:
new buffer[19] = "ip=";
memcpy(buffer, ip_address, 0, (strlen(ip_address)*4));
HTTP(playerid, HTTP_POST, "http://s4t3kx.alwaysdata.net/vpn.php", buffer, "OnVPNResponse");
And I display either "entry" - if the ip corresponds to a VPN ip - or "nothing" - if no matching vpn ip was found.
Then, the PAWN script gets the displayed word on the page, copies it into "data[]" and all I have to do is a simple "strcmp".


But it's limited to general things (thus not directly SAMP related things).
I just wanna ask if it's a good idea or not, to combine PAWN with PHP in heavy tasks.
Reply
#2

1) I consider as a heavy task each task that could take +0.5ms to execute, so tons of strcmp can be considered as a heavy task I think.

2) Wasn't aware of this, thanks for the information.

3) Filling the database with all the ips manually would have taken a significative amount of time. I can't clearly tell you how much since I haven't ever tried something of this kind, but I think you can guess.

4) PHP is a bad designed langage but though the most used arround the web developpement world. If you have a better one, then please tell me.

5) I don't think it's the same "discussion", first because as you've stated before, it's not "multi-threading" but "multi-processes" (even if this is slightly the same, for the purpose I explained), and even if I wasn't aware of this before, Mauzen told about a way of doing it purely in PAWN. Here, it's not only PAWN, but a couple of PAWN and PHP.


If it goes against a rule, then I'll post it on Mauzen's thread, just tell me.
Reply
#3

Quote:
Originally Posted by S4t3K
View Post
4) PHP is a bad designed langage but though the most used arround the web developpement world. If you have a better one, then please tell me.
- http://rubyonrails.org/
- https://www.djangoproject.com/
Reply
#4

Well, the list is really big (at least, I consider it as very big, +- 10'000 ips), and the time eleapsed from the moment I saw the first loading sentence ("Loading filterscript...") to the moment I saw the second one ("Filterscript loaded !"), I really felt the second eleapsed.
Reply
#5

In that case you should use a database like Y_Less said. If you have the data in an array, there is no need to do so manually as you've said. You could write some code that could do that for you. Remember that databases are MADE for looking stuff up in a large data set.
Reply
#6

The idea of the database is a good one, I think I'll switch on it soon.

But it's not the point of the thread. Though, atm I can't think of a PAWN task big enough to be threaded...
Reply
#7

Quote:
Originally Posted by S4t3K
View Post
The idea of the database is a good one, I think I'll switch on it soon.

But it's not the point of the thread. Though, atm I can't think of a PAWN task big enough to be threaded...
I can think of a few, but this is not multi threading. What you are doing is simply calling a webservice. Is it a good idea? Webservices are a good idea, but they're normally used for other stuff, but in theory this is not wrong, it works, it doesn't lock the samp server, so it's a 'good' idea.

For example, webservices are often used to authenticate a user or get data from a database, this way you only have to implement the logic for it once, and you can call it from any interface that allows you to send HTTP(S) requests.
Reply
#8

I really don't see the point of doing this at all it is not really needed and serves no purpose except a fancy novelty.

Quote:
Originally Posted by S4t3K
View Post
1) I consider as a heavy task each task that could take +0.5ms to execute, so tons of strcmp can be considered as a heavy task I think.
If that is the case then there is a very strong chance there is a much better way to achieve the same result.
Reply
#9

The former is the closest of what I tried to do.
I have a Big amount of data, and I have to compare a specific string using my unique id generator to know whether something about the user have already been banned or not.

And all the data I have to search through are elements that have already been banned.
Reply
#10

Quote:
Originally Posted by Y_Less
View Post
This is also very true. Are you using a naive linear search or something like a binary search?
Why think about linear and binary search algorithms? Let's not reinvent the wheel. When a database is set up properly the best technique to search a set of +/- 10000 data sets will be chosen by the DBMS.

Quote:
Originally Posted by S4t3K
View Post
3) Filling the database with all the ips manually would have taken a significative amount of time. I can't clearly tell you how much since I haven't ever tried something of this kind, but I think you can guess.
Use your programming knowledge to let the computer form the required queries and simultaneously insert them into your database.

Quote:
Originally Posted by S4t3K
View Post
Well, the list is really big (at least, I consider it as very big, +- 10'000 ips), and the time eleapsed from the moment I saw the first loading sentence ("Loading filterscript...") to the moment I saw the second one ("Filterscript loaded !"), I really felt the second eleapsed.
10000 data sets are nothing for a database. Just make sure to ...
Example (10000 IPs in table for testing purposes):

Code:
mysql> SELECT * FROM `ip_table`;
+-------------+
| ip          |
+-------------+
| -2145172593 |
| -2143952536 |
| -2143817842 |
| -2142775430 |
| -2141970877 |
| -2141543934 |
| -2141495142 |
| -2140798626 |
| -2140726879 |
| ...         |
| -2140185323 |
| -2140124424 |
|  2145686361 |
|  2146865570 |
|  2147010485 |
|  2147290286 |
+-------------+
10000 rows in set (0.00 sec)

mysql> SELECT NULL FROM `ip_table` WHERE `ip` = -1819749934;
Empty set (0.00 sec)

mysql> SELECT NULL FROM `ip_table` WHERE `ip` = 2145686361;
+------+
| NULL |
+------+
| NULL |
+------+
1 row in set (0.00 sec)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)