Jump to content



Photo

[FREE PLUGIN] Threads Counter - UBot v4 Threading Fixed

threading fixed counter v4

  • Please log in to reply
158 replies to this topic

#141 earthlingj

earthlingj

    Advanced Member

  • Fellow UBotter
  • PipPipPip
  • 208 posts
  • OS:Windows 8
  • Total Memory:< 1Gb
  • Framework:v3.5
  • License:Standard Edition

Posted 07 December 2014 - 07:54 AM

adding a stop wont work for me, because what i am doing is scraping 25 pages. then threading the process of posting on them. then when thread is back to 0. scrape next 25 pages. then thread to post on them. etc etc. 

 

plus, shouldnt thread count still be correct regardless? 



#142 UBotDev

UBotDev

    Advanced Member

  • Fellow UBotter
  • PipPipPip
  • 1395 posts
  • OS:Windows 10
  • Total Memory:More Than 9Gb
  • Framework:v3.5 & v4.0
  • License:Developer Edition

Posted 07 December 2014 - 09:42 AM

adding a stop wont work for me, because what i am doing is scraping 25 pages. then threading the process of posting on them. then when thread is back to 0. scrape next 25 pages. then thread to post on them. etc etc. 

 

Then you are not experiencing that problem (I guess you didn't read that post...the problem is related to part when bot reaches the end of script but won't stop).

You should still take that other suggestion into consideration...

 

Yes, threads should drop to 0.

 

I've stripped down your code a bit and threading itself works just fine (threads drop to 0 and alert is displayed), so I think you may have problems elsewhere. 

 

Here is the code:

loop(99999999) {
    set(#ThreadCount, $plugin function("Threads Counter.dll", "threads counter", "reset"), "Global")
    set(#Loops, 101, "Global")
    set(#ListItem, 0, "Global")
    loop(#Loops) {
        loop while($comparison(#ThreadCount, ">=", 10)) {
            wait(0.1)
        }
        set(#ThreadCount, $plugin function("Threads Counter.dll", "threads counter", "increment"), "Global")
        thread {
            set(#ThreadCount, $plugin function("Threads Counter.dll", "threads counter", "decrement"), "Global")
        }
        wait(0.1)
        increment(#ListItem)
    }
    loop while($comparison($plugin function("Threads Counter.dll", "threads counter", "read"), ">", 0)) {
        wait(5)
    }
    alert("")
}

What value does variable #Loops have on your side - are you opening too many threads?


CLICK UBotDev.com - Download FREE UBot Plugins!

______________________________________________

 


#143 earthlingj

earthlingj

    Advanced Member

  • Fellow UBotter
  • PipPipPip
  • 208 posts
  • OS:Windows 8
  • Total Memory:< 1Gb
  • Framework:v3.5
  • License:Standard Edition

Posted 07 December 2014 - 10:28 AM

Loops is the number of scraped posts ( usually between 20-30  )

Then you are not experiencing that problem (I guess you didn't read that post...the problem is related to part when bot reaches the end of script but won't stop).

You should still take that other suggestion into consideration...

 

Yes, threads should drop to 0.

 

I've stripped down your code a bit and threading itself works just fine (threads drop to 0 and alert is displayed), so I think you may have problems elsewhere. 

 

Here is the code:

loop(99999999) {
    set(#ThreadCount, $plugin function("Threads Counter.dll", "threads counter", "reset"), "Global")
    set(#Loops, 101, "Global")
    set(#ListItem, 0, "Global")
    loop(#Loops) {
        loop while($comparison(#ThreadCount, ">=", 10)) {
            wait(0.1)
        }
        set(#ThreadCount, $plugin function("Threads Counter.dll", "threads counter", "increment"), "Global")
        thread {
            set(#ThreadCount, $plugin function("Threads Counter.dll", "threads counter", "decrement"), "Global")
        }
        wait(0.1)
        increment(#ListItem)
    }
    loop while($comparison($plugin function("Threads Counter.dll", "threads counter", "read"), ">", 0)) {
        wait(5)
    }
    alert("")
}

What value does variable #Loops have on your side - are you opening too many threads?



#144 UBotDev

UBotDev

    Advanced Member

  • Fellow UBotter
  • PipPipPip
  • 1395 posts
  • OS:Windows 10
  • Total Memory:More Than 9Gb
  • Framework:v3.5 & v4.0
  • License:Developer Edition

Posted 07 December 2014 - 11:28 AM

As you can see in this video, the code I've posted above works fine, that's why I think there is nothing wrong with threading...I guess it may be your code/setup.

 

Does the code above work for you or not? What version of UBot are you using? Maybe you should share the whole code, since this part seems to work ok....


CLICK UBotDev.com - Download FREE UBot Plugins!

______________________________________________

 


#145 earthlingj

earthlingj

    Advanced Member

  • Fellow UBotter
  • PipPipPip
  • 208 posts
  • OS:Windows 8
  • Total Memory:< 1Gb
  • Framework:v3.5
  • License:Standard Edition

Posted 07 December 2014 - 07:31 PM

it works fine at the beginning but if you leave it running for a while ( after a few hours ) thats when the thread counter goes off

 

 

in one of my other bots, the thread counter sometimes even goes in the negative after a while.  

 

 

 

also, as for passing the list item in a define? why that instead of local dictionary? I thought local dictionary is thread safe?



#146 UBotDev

UBotDev

    Advanced Member

  • Fellow UBotter
  • PipPipPip
  • 1395 posts
  • OS:Windows 10
  • Total Memory:More Than 9Gb
  • Framework:v3.5 & v4.0
  • License:Developer Edition

Posted 09 December 2014 - 12:46 PM

I've been running bots with thread counter for days and I haven't noticed anything like that. I also left the code above running for some time an nothing.

 

Whatever you use you need to use define command to ensure that value you pass in doesn't changes when a new thread is about to start. Local dictionary being thread safe has nothing to do with this....


CLICK UBotDev.com - Download FREE UBot Plugins!

______________________________________________

 


#147 earthlingj

earthlingj

    Advanced Member

  • Fellow UBotter
  • PipPipPip
  • 208 posts
  • OS:Windows 8
  • Total Memory:< 1Gb
  • Framework:v3.5
  • License:Standard Edition

Posted 10 December 2014 - 08:50 AM

I changed it to use define like you said and it makes no difference. After hours of running, the thread counter ends up being off still. 

 

and the reason i said local dictionary is because you are sayuing define so that the value passed doesnt change, but local dictionary value shouldnt change either within the thread. 



#148 UBotDev

UBotDev

    Advanced Member

  • Fellow UBotter
  • PipPipPip
  • 1395 posts
  • OS:Windows 10
  • Total Memory:More Than 9Gb
  • Framework:v3.5 & v4.0
  • License:Developer Edition

Posted 10 December 2014 - 10:04 AM

Strange...I can't reproduce it so I can't do anything to help you....

 

Again, local dictionary has nothing to do with that....the problem is in UBot variable "#ListItem" that you are passing to thread, and that value can change for thread because you are not using define command.

 

EDIT: If you still need confirmation about define commands, Dan wrote a post about that recently: http://www.ubotstudi...with-threading/


CLICK UBotDev.com - Download FREE UBot Plugins!

______________________________________________

 


#149 earthlingj

earthlingj

    Advanced Member

  • Fellow UBotter
  • PipPipPip
  • 208 posts
  • OS:Windows 8
  • Total Memory:< 1Gb
  • Framework:v3.5
  • License:Standard Edition

Posted 10 December 2014 - 01:11 PM

Its strange because i changed it to use defines and now after just 100 posts im at -2 threads and it stopped instead of continuing 1000s



#150 UBotDev

UBotDev

    Advanced Member

  • Fellow UBotter
  • PipPipPip
  • 1395 posts
  • OS:Windows 10
  • Total Memory:More Than 9Gb
  • Framework:v3.5 & v4.0
  • License:Developer Edition

Posted 10 December 2014 - 08:08 PM

The only thing I see is that you should read thread count with plugin on problematic places, not by reading UBot variable...refering to this line of code (#ThreadCount doesn't have up to date info on threads count):

loop while($comparison(#ThreadCount, ">=", 10)) {

If threads go down to negative values I'm sure you are decrementing thread counter more often than you should (you haven't shared the whole code, so problem may be elsewhere).

 

Without a way to reproduce the problem I can't really help you.


CLICK UBotDev.com - Download FREE UBot Plugins!

______________________________________________

 


#151 earthlingj

earthlingj

    Advanced Member

  • Fellow UBotter
  • PipPipPip
  • 208 posts
  • OS:Windows 8
  • Total Memory:< 1Gb
  • Framework:v3.5
  • License:Standard Edition

Posted 12 December 2014 - 07:43 AM

Okay i changed it to use the thread counter read instead of by variable and its still miscounting. I changed my thread code to be exactly like your example as well with the only difference being my define command. the thread counts are all outside of my define so nothing within the define code should be messing up the thread counter....



#152 Bot-Factory (Dan)

Bot-Factory (Dan)

    Advanced Member

  • Fellow UBotter
  • PipPipPip
  • 2974 posts
  • LocationEurope/Germany
  • OS:Windows 8
  • Total Memory:8Gb
  • Framework:v4.0
  • License:Developer Edition

Posted 12 December 2014 - 10:04 AM

Okay i changed it to use the thread counter read instead of by variable and its still miscounting. I changed my thread code to be exactly like your example as well with the only difference being my define command. the thread counts are all outside of my define so nothing within the define code should be messing up the thread counter....

Please share the code where we can reproduce that problem. Then we are able to help you.

Kindest regards

Dan


Signature-JPG.jpg


#153 earthlingj

earthlingj

    Advanced Member

  • Fellow UBotter
  • PipPipPip
  • 208 posts
  • OS:Windows 8
  • Total Memory:< 1Gb
  • Framework:v3.5
  • License:Standard Edition

Posted 17 December 2014 - 06:22 AM

i removed threadcounter reset in the beginning of my loop and now it works much better, but still goes off sometimes. 

 

i have another bot i run 50 threads on and that one is always off. 



#154 earthlingj

earthlingj

    Advanced Member

  • Fellow UBotter
  • PipPipPip
  • 208 posts
  • OS:Windows 8
  • Total Memory:< 1Gb
  • Framework:v3.5
  • License:Standard Edition

Posted 19 December 2014 - 06:24 AM

yZJckir.png

 

its not thread safe. 



#155 Bot-Factory (Dan)

Bot-Factory (Dan)

    Advanced Member

  • Fellow UBotter
  • PipPipPip
  • 2974 posts
  • LocationEurope/Germany
  • OS:Windows 8
  • Total Memory:8Gb
  • Framework:v4.0
  • License:Developer Edition

Posted 19 December 2014 - 06:38 AM

yZJckir.png

 

its not thread safe. 

 

The plugin works fine. Your code might be the problem.
But as mentioned a couple of times, without showing us your code, we can't help you.

Give us some Ubot code that allows us to reproduce the error please. Without code, there is nothing we can discuss.  :blink:

 

 

Dan


Signature-JPG.jpg


#156 earthlingj

earthlingj

    Advanced Member

  • Fellow UBotter
  • PipPipPip
  • 208 posts
  • OS:Windows 8
  • Total Memory:< 1Gb
  • Framework:v3.5
  • License:Standard Edition

Posted 25 December 2014 - 01:29 PM

im using the exact same code in the demo here. the problem is the DECREMENTING thread count. it really doesnt seem to be thread safe. I dont want to share my full source for obvious reasons, but what i can say is.. im 100% using the exact demo in this thread and im not new to ubot ive been doing this a long time. unless defines sometimes randomly get skipped, there is no reason for the thread count to be off other than it not being thread safe and decrementing ' at the same time' which is throwing off the count. 



#157 UBotDev

UBotDev

    Advanced Member

  • Fellow UBotter
  • PipPipPip
  • 1395 posts
  • OS:Windows 10
  • Total Memory:More Than 9Gb
  • Framework:v3.5 & v4.0
  • License:Developer Edition

Posted 26 December 2014 - 01:55 AM

No one else except you is having this problem or is being able to reproduce it. While you can't share your code we also can't help you "because of the obvious reasons"

 

You've been doing UBot for long time.....but you made the most basic mistake with threading, while you didn't use a define command around thread. With such a basic mistake I think you still have some problems understanding threading in UBot, that's why I think the problem is actually in your code and not with the plugin; If you would read the post about how threads counter does it's job and understand the C# code behind, you would know that it is indeed thread safe...I guess there could be a small chance that UBot would make in unsafe (via their plugin API), but I doubt that's the case (again, never had problems with the plugin).

 

P.S.: To solve this....maybe try your code in Ubot v5, where you don't need threads counter anymore, since threading seems to be fixed there (although I've decided to still use threads counter in v5 until it becomes more stable, so I can revert to v4 any time).


CLICK UBotDev.com - Download FREE UBot Plugins!

______________________________________________

 


#158 acamso

acamso

    Advanced Member

  • Fellow UBotter
  • PipPipPip
  • 356 posts
  • OS:Windows 8
  • Total Memory:6Gb
  • Framework:v3.5 & v4.0
  • License:Developer Edition

Posted 29 January 2015 - 11:31 AM

UbotDev, as discussed in PM, I was wondering if it were possible to have multiple counters. I use the thread counter mainly for list positions as it increments and sets the list position in one shot to avoid conflicts. However, I'd like to run multiple tasks at one time that both use the threads counter, so it would be great if it were possible to have multiple counters. Thanks

acamso-logo.png


#159 acamso

acamso

    Advanced Member

  • Fellow UBotter
  • PipPipPip
  • 356 posts
  • OS:Windows 8
  • Total Memory:6Gb
  • Framework:v3.5 & v4.0
  • License:Developer Edition

Posted 07 April 2015 - 05:46 AM

Hey.. I will pay you extra for multiple counters. Please let me know


acamso-logo.png






Also tagged with one or more of these keywords: threading, fixed, counter, v4

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users