Jump to content
UBot Underground

[FREE PLUGIN] Threads Counter - UBot v4 Threading Fixed


Recommended Posts

As you may be aware threading in UBot v4 is not safe and may not work as expect under certain conditions, which would result in threads slowly dying out, so at the end, you only get left with 1 active thread, although you coded the bot to run with multiple (problem explained here). Threads Counter plugin was created to solve threading problems in UBot v4 by providing a dedicated Threads Counter to your UBot environment which allows you to implement threading properly.

 

"$threads counter" function allows you to perform 4 different operations, which can be seen on image bellow, and are quite self explanatory.

 

http://ubotdev.com/wp-content/uploads/2013/11/threads-counter-289x300.png

 

For more information about Threads Counter plugin please visit this page:

http://ubotdev.com/free-plugin-threads-counter

Direct download

 

EXAMPLE: Scraper With Proxies and Multiple Threads

The code bellow will scrape some details about your proxy from "whatsmyip.com", with 1 proxy per thread. To test the code please copy paste it to UBots "code view", save it to a file, and save your proxies to "proxies.txt" file, which should be located in the same folder where you saved UBot file. After that you are ready to run the code. Read more: http://ubotdev.com/free-plugin-threads-counter#scraper-with-proxies-and-multiple-threads

ui drop down("Threads", "10,20,30,40,50", #INPUT Threads)
ui stat monitor("Threads (Active/Total):", "<b>{#THREADS Active}/{#THREADS Max}</b>")
ui stat monitor("COUNT:", #COUNT)
set(#FOLDER Root, $special folder("Application"), "Global")
set(#THREADS Max, #INPUT Threads, "Global")
clear table(&RESULTS)
add list to table as row(&RESULTS, 0, 0, $list from text("Proxy Used,IP,Proxy,City,Country,ISP,STATUS", ","))
set(#RESULTS ROW, 1, "Global")
clear list(%PROXIES)
add list to list(%PROXIES, $list from file("{#FOLDER Root}\\proxies.txt"), "Delete", "Global")
set(#PROXIES ROW, 0, "Global")
set(#COUNT, $list total(%PROXIES), "Global")
if($comparison(#THREADS Max, ">", #COUNT)) {
    then {
        alert("You need to have more proxies than threads.")
        stop script
    }
    else {
    }
}
comment("Reset counter to 0.")
set(#THREADS Active, $plugin function("Threads Counter.dll", "threads counter", "reset"), "Global")
comment("Main Threading Loop")
loop while($comparison(#COUNT, ">", 0)) {
    if($comparison($plugin function("Threads Counter.dll", "threads counter", "read"), "<", #THREADS Max)) {
        then {
            comment("Increment Number Of Threads And Store Value to UBot Variable.")
            set(#THREADS Active, $plugin function("Threads Counter.dll", "threads counter", "increment"), "Global")
            if($comparison(#PROXIES ROW, ">=", $list total(%PROXIES))) {
                then {
                    set(#PROXIES ROW, 0, "Global")
                }
                else {
                }
            }
            THREAD START(#PROXIES ROW, #RESULTS ROW)
            increment(#PROXIES ROW)
            increment(#RESULTS ROW)
            decrement(#COUNT)
        }
        else {
            wait(0.2)
        }
    }
}
comment("Thread Command")
define THREAD START(#PROXIES ROW, #RESULTS ROW) {
    thread {
        in new browser {
            CHANGE PROXY(#PROXIES ROW)
            SCRAPE WHATSMYIP(#PROXIES ROW, #RESULTS ROW)
        }
        set(#THREADS Active, $plugin function("Threads Counter.dll", "threads counter", "decrement"), "Global")
    }
}
comment("Wait For Threads To Close")
set(#THREADS Active, $plugin function("Threads Counter.dll", "threads counter", "read"), "Global")
loop while($comparison(#THREADS Active, ">", 0)) {
    set(#THREADS Active, $plugin function("Threads Counter.dll", "threads counter", "read"), "Global")
    wait(2)
}
save to file("{#FOLDER Root}\\results.csv", &RESULTS)
stop script
define CHANGE PROXY(#PROXIES ROW) {
    clear list(%PROXY)
    add list to list(%PROXY, $list from text($list item(%PROXIES, #PROXIES ROW), ":"), "Don\'t Delete", "Global")
    if($comparison($list total(%PROXY), "=", 4)) {
        then {
            set proxy credentials($list item(%PROXY, 2), $list item(%PROXY, 3))
            change proxy("{$list item(%PROXY, 0)}:{$list item(%PROXY, 1)}")
        }
        else if($comparison($list total(%PROXY), "=", 2)) {
            change proxy("{$list item(%PROXY, 0)}:{$list item(%PROXY, 1)}")
        }
        else {
            alert("Proxy on row #{#PROXIES ROW} is invalid.")
            stop script
        }
    }
}
define SCRAPE WHATSMYIP(#PROXIES ROW, #RESULTS ROW) {
    navigate("http://www.whatismyip.com/", "Wait")
    wait for browser event("DOM Ready", "")
    wait for element(<class="the-ip">, "", "Appear")
    if($exists(<class="the-ip">)) {
        then {
            set table cell(&RESULTS, #RESULTS ROW, 0, $list item(%PROXIES, #PROXIES ROW))
            set table cell(&RESULTS, #RESULTS ROW, 1, $scrape attribute(<class="the-ip">, "innertext"))
            set table cell(&RESULTS, #RESULTS ROW, 2, $scrape attribute(<class="the-proxy">, "innertext"))
            set table cell(&RESULTS, #RESULTS ROW, 3, $scrape attribute(<class="the-city">, "innertext"))
            set table cell(&RESULTS, #RESULTS ROW, 4, $scrape attribute(<class="the-country">, "innertext"))
            set table cell(&RESULTS, #RESULTS ROW, 5, $scrape attribute(<class="the-isp">, "innertext"))
            set table cell(&RESULTS, #RESULTS ROW, 6, "SUCCESS")
        }
        else {
            set table cell(&RESULTS, #RESULTS ROW, 6, "FAIL")
        }
    }
}

EXAMPLE: Threads Counter Unit Test

Please use example above (Scraper With Proxies and Multiple Threads) while it's easier to adopt for standard threading setup with UBot.

If you insist on using this code don't forget to replace "#COUNT" variable with you real count number and remove the timeout at the end, when waiting for all threads to close "$comparison(#WAIT Count, "<", 10".

ui drop down("COUNT", "100,1000,10000", #Input Count)
ui drop down("Threads", "10,20,30,40,50", #INPUT Threads)
ui stat monitor("Threads (Active/Total):", "<b>{#THREADS Active}/{#THREADS Max}</b>")
ui stat monitor("COUNT:", #COUNT)
set(#COUNT, #Input Count, "Global")
set(#THREADS Max, #INPUT Threads, "Global")
comment("Reset counter to 0.")
set(#THREADS Active, $plugin function("Threads Counter.dll", "threads counter", "reset"), "Global")
comment("Main Threading Loop")
loop while($comparison(#COUNT, ">", 0)) {
    if($comparison($plugin function("Threads Counter.dll", "threads counter", "read"), "<", #THREADS Max)) {
        then {
            comment("Increment Number Of Threads And Store Value to UBot Variable.")
            set(#THREADS Active, $plugin function("Threads Counter.dll", "threads counter", "increment"), "Global")
            THREAD START()
            decrement(#COUNT)
        }
        else {
            wait(0.2)
        }
    }
}
comment("Thread Command")
define THREAD START {
    thread {
        comment("While This Is Only A Test We Only Delay Here.")
        wait(0.5)
        comment("Decrement Number Of Threads And Store Value to UBot Variable.")
        set(#THREADS Active, $plugin function("Threads Counter.dll", "threads counter", "decrement"), "Global")
    }
}
comment("Wait For Threads To Close Or Timeout After 20 seconds.")
set(#THREADS Active, $plugin function("Threads Counter.dll", "threads counter", "read"), "Global")
set(#WAIT Count, 0, "Global")
loop while($both($comparison(#THREADS Active, ">", 0), $comparison(#WAIT Count, "<", 10))) {
    set(#THREADS Active, $plugin function("Threads Counter.dll", "threads counter", "read"), "Global")
    increment(#WAIT Count)
    wait(2)
}
comment("Check How Many Threads UBot Sees.")
if($comparison(#THREADS Active, ">", 0)) {
    then {
        alert("Some threads were not closed/decremented properly.")
    }
    else {
        alert("All threads were closed")
    }
}
  • Like 6
Link to post
Share on other sites
  • Replies 161
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

As you may be aware threading in UBot v4 is not safe and may not work as expect under certain conditions, which would result in threads slowly dying out, so at the end, you only get left with 1 active

Awesome plugin UBotDev

You are not using the plugin from the title, instead you are using the plugin that Blumi 40 keeps posting here (Blumi40, can you please open another thread for that plugin instead of discussing it her

thx for this nice plugin
but i thing u also could solve the problem with the TinyMCE plugin which offer the "Thread safe Container" u can use that container inside a thread  everytime u do things 100% exclusiv

i havend test it yet with a counter but im sure that works well too

Link to post
Share on other sites

thx for this nice plugin

but i thing u also could solve the problem with the TinyMCE plugin which offer the "Thread safe Container" u can use that container inside a thread  everytime u do things 100% exclusiv

i havend test it yet with a counter but im sure that works well too

yeah that worked pretty well good plugin until you increase to high threads. the problem is there is two issues the first is more than one thread accessing the variable and the second is ubot variables don't increment quick enough so even with a thread safe container sometimes the increment gets missed. tried this plugin solves the problem works well.

Link to post
Share on other sites

yeah that worked pretty well good plugin until you increase to high threads. the problem is there is two issues the first is more than one thread accessing the variable and the second is ubot variables don't increment quick enough so even with a thread safe container sometimes the increment gets missed. tried this plugin solves the problem works well.

Thread safe Container blocks access to vars lists tables as long the routine inside is running!

so if some another routine want have access to it have to wait untill is unlocked.

Systemwide Thread safe Container does this action Systemwide  means if u work same time with different bots on the same table/list and u have a save or read action  the container block access to all bots untill his job is done   condition is that lists and tables who needs that routin should name same... it works 100% i was use that many many times

Link to post
Share on other sites

thx for this nice plugin

but i thing u also could solve the problem with the TinyMCE plugin which offer the "Thread safe Container" u can use that container inside a thread  everytime u do things 100% exclusiv

i havend test it yet with a counter but im sure that works well too

As I have already mentioned that plugin doesn't work for me: http://www.ubotstudio.com/forum/index.php?/topic/15122-must-read-threading-doesnt-work-as-expected-tested-in-v4/page-2&do=findComment&comment=86899

Link to post
Share on other sites

dont know which version u use  but if u use the latest   u can set a memory free function in the 0.2sec else condition.

i saw a little mistake too if i use 10tsd and 50 threads but with the clear ubot memory option that will solve that too

 

Link to post
Share on other sites

dont know which version u use  but if u use the latest   u can set a memory free function in the 0.2sec else condition.

i saw a little mistake too if i use 10tsd and 50 threads but with the clear ubot memory option that will solve that too

 

 

I used the version that was available at the time when I found the problem (1 month ago) but it didn't solve the problem as you can read on another post, where we already talked about that. In the video you can clearly see that I'm getting errors when executing that code.

 

Do we need to discuss it here again?

 

I'm not forcing anyone to use this plugin, I made it for my own needs and wanted to share it with the community. If that plugin works for you then use that one...

Link to post
Share on other sites

I used the version that was available at the time when I found the problem (1 month ago) but it didn't solve the problem as you can read on another post, where we already discussed that. In the video you can clearly see that I'm getting errors when executing that code.

 

Do we need to discuss it here again?

Shame over me :)

i was trying to help.... i know what time it need to code a plugin so u got 100% my respect for give that the the folks for free

but i also knows that a plugin more needs more time to load ubot bots.

so if u dont like my solution i can lif with and sorry that noone knows about the new version...i only use it im not the broadcaster for that plugin so i realy dont know which release ppl are use.

 

and again i respect what u did i only was trying search for another solution that was my intension

Link to post
Share on other sites

Shame over me :)

i was trying to help.... i know what time it need to code a plugin so u got 100% my respect for give that the the folks for free

but i also knows that a plugin more needs more time to load ubot bots.

so if u dont like my solution i can lif with and sorry that noone knows about the new version...i only use it im not the broadcaster for that plugin so i realy dont know which release ppl are use.

 

and again i respect what u did i only was trying search for another solution that was my intension

I appreciate that.

 

I also respect you and developer behind the plugin, but unfortunately there is no documentation and there is no support provided for that plugin (no one had time to explain what's going on with those errors?), which makes it hard or even impossible to use (like in my case where I wasn't able to get rid of those error popups).

 

Also, there was only 1 person who claimed that it's working at the time so I can't know if it's working or not based on that feedback, it's 1 vs 1, and I proved mine to work with the similar code.

Link to post
Share on other sites

im totaly with u  belive me.... i would write a manual for, but my english is to bad for that.
i always try my best to explane some of the features but at the end it isnt my plugin, i only was the guy who wrotes some examples how to use some functions of it

Link to post
Share on other sites

awesome plugin! although i seem to still have issues with thread counts. i used your exact demo script. I tried with 50 and 100 threads and the thread count was off as well a some of the error pop ups http://prntscr.com/25cdc0

You are not using the plugin from the title, instead you are using the plugin that Blumi 40 keeps posting here (Blumi40, can you please open another thread for that plugin instead of discussing it here? ...you are only confusing people).

 

I've had the exact same problem with the plugin you are using, that's why I created this new plugin called "Threads Counter".

 

Earthlingj, please use my plugin instead and let me know if it solved the problems for you.

  • Like 1
Link to post
Share on other sites

Ran some more tests. 

 

seems like if you use 'in new browser' you get that local tmp file error... once i removed it i didnt get that error anymore. 

 

secondly, check out this code below. all i did was add a variable "jesus" and an increment. at the end of the run jesus should = whatever COUNT you set, but when running with 100 threads its way off. i then tried adding thread safe container to the increment jesus and still off. so thread safe container is not working 100% i dont think as other people have stated. 

 

 

 

ui drop down("COUNT""100,1000,10000"#Input Count)
ui drop down("Threads""10,20,30,40,50,100,250"#INPUT Threads)
ui stat monitor("Threads (Active/Total):""<b>{#THREADS Active}/{#THREADS Max}</b>")
ui stat monitor("COUNT:"#COUNT)
set(#COUNT#Input Count"Global")
set(#THREADS Max#INPUT Threads"Global")
comment("Reset counter to 0.")
set(#THREADS Active$plugin function("Threads Counter.dll""threads counter""reset"), "Global")
comment("Main Threading Loop")
plugin command("HTTP post.dll""http cookies folder""C:\\Cookies")
set(#jesus, 0, "Global")
loop while($comparison(#COUNT">", 0)) {
    if($comparison(#THREADS Active"<"#THREADS Max)) {
        then {
            comment("Increment Number Of Threads And Store Value to UBot Variable.")
            set(#THREADS Active$plugin function("Threads Counter.dll""threads counter""increment"), "Global")
            THREAD START()
            decrement(#COUNT)
        }
        else {
            wait(0.2)
        }
    }
}
comment("Thread Command")
define THREAD START {
    thread {
        wait(0.5)
        comment("Decrement Number Of Threads And Store Value to UBot Variable.")
        set(#THREADS Active$plugin function("Threads Counter.dll""threads counter""decrement"), "Global")
        plugin command("Open.Framework.dll""Thread safe container") {
            increment(#jesus)
        }
    }
}
comment("Wait For Threads To Close Or Timeout After 20 seconds.")
set(#THREADS Active$plugin function("Threads Counter.dll""threads counter""read"), "Global")
set(#WAIT Count, 0, "Global")
loop while($both($comparison(#THREADS Active">", 0), $comparison(#WAIT Count"<", 10))) {
    set(#THREADS Active$plugin function("Threads Counter.dll""threads counter""read"), "Global")
    increment(#WAIT Count)
    wait(2)
}
comment("Check How Many Threads UBot Sees.")
if($comparison(#THREADS Active">", 0)) {
    then {
        alert("Some threads were not closed/decremented properly.")
    }
    else {
        alert("All threads were closed")
    }
}
Link to post
Share on other sites

You are not using the plugin from the title, instead you are using the plugin that Blumi 40 keeps posting here (Blumi40, can you please open another thread for that plugin instead of discussing it here? ...you are only confusing people).

 

I've had the exact same problem with the plugin you are using, that's why I created this new plugin called "Threads Counter".

 

Earthlingj, please use my plugin instead and let me know if it solved the problems for you.

 

I've tested with both. It seems to happen only when using 'in new browser'. that threw off the thread count as well as the tmp error. when i removed in new browser it worked without error.

Link to post
Share on other sites

I've tested with both. It seems to happen only when using 'in new browser'. that threw off the thread count as well as the tmp error. when i removed in new browser it worked without error.

That error is produced by the other plugin, since I'm not saving any data to files....

 

Please remove the other plugin and test this one only; I can't provide you any help with the 2nd plugin, since I'm not the author, so please open another thread for that one here on forum.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...