← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #191167]: [Java] Mouse/keyboard choppiness when using concurrent threads

 

Question #191167 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/191167

Jacob Dorman posted a new comment:
I've duplicated the issue in a Sikuli project.  In my original program,
I had 2 threads during many operations, and got Sikuli command lag.  In
this test program I used 3-4 observers before duplicating my results
very noticeably.

The program itself simply has 1 dummy pattern that is looked for by 4
observers.   There's an observer for every quadrant of the screen (in
graph speak).  The program highlights each quadrant, and then begins
looking for the dummy pattern.  In the almost impossible chance that it
finds the pattern (it's pretty random, and 1.00 similarity), the event
just passes.

There's an event for each observer to more accurately represent observer
usage.  In my tests, having multiple events for the observers instead of
just one event seems to slow the mouse down even more, but that may not
be typical.

While the 4 observers observe, the main thread moves the mouse in a
rectangle 3 times to test the responsiveness.  After completing 3
rectangles, the observers are stopped, and the mouse makes another 3
rectangles to show the difference in responsiveness.

On my machine, the main thread executes so slowly at times that
click/type commands can fail to work properly.

You can download the 4KB .sikuli project here:
http://www.mediafire.com/?oi2pf9gfbbwveai
or just use the source directly below:

#Test program to show that concurrent threads can slow mouse operations
#Jacob Dorman

#dummy pattern
dummy = Pattern("dummy-pattern1.png").exact()
#Create the initial region
firstQuadrant = Region(SCREEN.w/2, 0, SCREEN.w/2, SCREEN.h/2)
firstQuadrant.highlight(1)
#First threaded section (1st quadrant)
def dummyEventOne(event):
    pass

firstQuadrant.onAppear(dummy, dummyEventOne)
firstQuadrant.observe(FOREVER,background = True)

#Second threaded section (2nd quadrant)
def dummyEventTwo(event):
    pass
       
secondQuadrant = Region(0, 0, SCREEN.w/2, SCREEN.h/2)
secondQuadrant.highlight(1)
secondQuadrant.onAppear(dummy, dummyEventTwo)
secondQuadrant.observe(FOREVER, background = True)

#Third threaded section (3rd quadrant)
def dummyEventThree(event):
    pass
thirdQuadrant = Region(0, SCREEN.h/2, SCREEN.w/2, SCREEN.h/2)
thirdQuadrant.highlight(1)
thirdQuadrant.onAppear(dummy, dummyEventThree)
thirdQuadrant.observe(FOREVER, background = True)

#Fourth threaded section (4th quadrant)
def dummyEventFour(event):
    pass
fourthQuadrant = Region(SCREEN.w/2, SCREEN.h/2, SCREEN.w/2, SCREEN.h/2)
fourthQuadrant.highlight(1)
fourthQuadrant.onAppear(dummy, dummyEventFour)
fourthQuadrant.observe(FOREVER, background = True)

#Main thread, moves the mouse in a rectangle
count = 0
while (count < 3):
    hover(Env.getMouseLocation().above(200))
    hover(Env.getMouseLocation().left(200))
    hover(Env.getMouseLocation().below(200))
    hover(Env.getMouseLocation().right(200))
    count = count + 1
#Stop the threads to show normal Sikuli speed with the same operation
firstQuadrant.stopObserver()
secondQuadrant.stopObserver()
thirdQuadrant.stopObserver()
fourthQuadrant.stopObserver()

count = 0
while (count < 3):
    hover(Env.getMouseLocation().above(200))
    hover(Env.getMouseLocation().left(200))
    hover(Env.getMouseLocation().below(200))
    hover(Env.getMouseLocation().right(200))
    count = count + 1

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.