Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Welcome to the Monastery
 
PerlMonks  

Re: Perl tk gui hangs when large data thrown to it

by BrowserUk (Pope)
on Oct 15, 2013 at 09:03 UTC ( #1058276=note: print w/ replies, xml ) Need Help??


in reply to Perl tk gui hangs when large data thrown to it

I continuosly want to change some 1000 rows on the gui at every millisecond.

You want to perform 1 million updates per second to your gui ...

I can not put the entire code here, but i am putting some snippets of it to explain you better

And you've omitted the code for what is likely the most critical routine in the program: updateDisplay($databuf);

I need to know what is the possible reason for the gui to get hung and how can this be overcomed ?

And you want us to guess where the problem originates and how to fix it?

In all probability your first problem is that it is extremely doubtful that your system is capable of achieving a 1 million tcp packets/sec throughput.

The next is (probably) that if you ran a tight loop in your gui, that randomly generated your row/color/state messages and directly modified your gui accordingly, that it would only achieve a few thousands of updates per second at best.

Both of the above are very easy tests for you to perform; and will likely convince you that your expectations are unrealistic.

If you want help that is more than guesswork; you'll need to give us something that we can run.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re: Perl tk gui hangs when large data thrown to it
Download Code
Re^2: Perl tk gui hangs when large data thrown to it
by Anonymous Monk on Oct 15, 2013 at 10:54 UTC
    can you give me any email address or the like so that I can send you some files otherwise the code is too huge to include here.
      the code is too huge to include here.

      Simplify it. That is, make a simplified version of it for testing. Just the single widget that displays your changing data, the timer routine that processes inbound packets and the updateDisplay() routine. This would be invaluable to you for testing the maximum throughput you can expect of Tk and your tcp code.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Well, even the simplified version will be quite long. I have described the entire thing here, but may be it is not sufficient for you to guess.
        FYI, I am giving the update gui routine here, which is getting called from the server function as and when it has read some data from the socket.

        sub updateGui { my $self = shift; my $data = shift; my $hlist = $self->{jobTree}; my @cellInfo = split( /\s/, $data ); my $font = "{helvetica} -12 bold"; my $style1 = $self->{displaybaseObj}->getItemStyle( $hlist, 'text', -foreground => 'black', -anchor => 'nw', -background => "$cellInfo[2]", -font => $font ); my $num1 = int( rand(2) ) + 1; my $num2 = int( rand(2) ) + 0; my $subnode1 = $cellInfo[0] . "." . $num1; my $subnode2 = $cellInfo[0] . "." . $num1 . "." . "0" . "." . $num +2; $hlist->itemConfigure( $subnode1, 2, -text => "$cellInfo[1]", -style => $style1 ); $hlist->itemConfigure( $subnode2, 2, -text => "$cellInfo[1]", -style => $style1 ); }

        The $data to this routine is like "500 running green" i.e a gui row , some status of that and a colour separated by single space. $hlist is the Tree widget which just a bit extension of the built in HList.pm Tk module.

        Let me see , if I can post a very simplified version of it.

        I am just including a very very simplified code which is just one perl file only. Please change the repeat frequency to test it. The gui would show better performance if the repeat frequency is increased to 1sec , currently it is 1ms only.
        My requirement is :

        1. what is the reason for the gui to get hung when we are trying to change some 100 rows on it every 1 ms . Can not perl tk handle this ? is this a limitation ?

        2. is their any other mechanism to make it work, provided i will repeat it every 1 ms and would try to change 100 rows of it randomly.

        use Tk; use Tk::HList; use Time::HiRes qw/usleep/; my $mw = MainWindow->new(); my $hlistframe = $mw->Frame()->pack( -fill => 'both', -expand => 1 ); my $font = "{helvetica} -12 bold"; my $hl = $hlistframe->Scrolled( 'HList', -scrollbars => 'ose', -columns => 7, -header => 1, #-height => 10, -width => 50, -command => sub { print "test\n"; }, )->pack( -fill => 'both', -expand => 1 ); my $num = $hl->Label( -text => "Number", -anchor => 'w', -font => $fon +t ); $hl->headerCreate( 0, -itemtype => 'window', -widget => $num ); my $name = $hl->Label( -text => "ID", -anchor => 'w', -font => $font ) +; $hl->headerCreate( 1, -itemtype => 'window', -widget => $name ); my $DOB = $hl->Label( -text => "Job", -anchor => 'w', -font => $font ) +; $hl->headerCreate( 2, -itemtype => 'window', -widget => $DOB ); my $Address = $hl->Label( -text => "status", -anchor => 'w', -font => +$font ); $hl->headerCreate( 3, -itemtype => 'window', -widget => $Address ); my $style1 = $hl->ItemStyle( 'text', -selectforeground => 'black', -anchor => 'nw', -background => 'green', -font => $font ); my $style2 = $hl->ItemStyle( 'text', -selectforeground => 'black', -anchor => 'nw', -background => 'red', -font => $font ); my $style3 = $hl->ItemStyle( 'text', -selectforeground => 'black', -anchor => 'nw', -background => 'blue', -font => $font ); sub populate { my $path = 0; foreach my $entry ( 1 .. 100 ) { insertData( $path, $entry ); $path++; } } &populate(); sub insertData { my ( $path, $entry ) = @_; $hl->add($path); # print "path $path \n"; $hl->itemCreate( $path, 0, -text => "$path" ); # , -style => $ +style1); $hl->itemCreate( $path, 1, -text => "someid" ); # , -style => $ +style1); $hl->itemCreate( $path, 2, -text => "test" ); #, -style => $s +tyle1); $hl->itemCreate( $path, 3, -text => "running", -style => $style1 ) +; } $mw->repeat( 1, \&changeItem ); my $flag; sub changeItem { my %flag; foreach ( 1 .. 100 ) { my $randRow = int( rand(20) ); print "randRow $randRow \n"; if ( $flag{$randRow} ) { $hl->itemConfigure( $randRow, 3, -text => "pending", -style => $style2 ); $hl->itemConfigure( $randRow, 3, -text => "waiting", -style => $style2 ); $flag{$randRow} = 0; print "if flag ", $flag{$randRow}, "\n"; } else { print "else flag 0\n"; $hl->itemConfigure( $randRow, 3, -text => "finished", -style => $style3 ); $hl->itemConfigure( $randRow, 3, -text => "aborted", -style => $style3 ); $flag{$randRow} = 1; print "else flag ", $flag{$randRow}, " \n"; } #usleep(100); #sleep 2 ; } } MainLoop;
      NO!

      As others have recommended: Simplify; create an example which illustrates the problem with fewer than 20 lines; (and, p.s. - don't whine).

      It's an extremely rare problem in this class that can't be duplicated without more than a few lines of code; in any case, the exercise of creating a brief example may illuminate your problem for you.

      My 'oops': intended as first reply to request (at Re^2: Perl tk gui hangs when large data thrown to it) for an email address.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1058276]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (11)
As of 2014-04-18 09:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (464 votes), past polls