FutureQuest, Inc. FutureQuest, Inc. FutureQuest, Inc.

FutureQuest, Inc.
Go Back   FutureQuest Community > General Site Owner Support (All may read/respond) > General Coding/Development
User Name
Password  Lost PW

Reply
 
Thread Tools Search this Thread Display Modes
Old 11-05-2018, 02:15 PM   Postid: 186787
ricktrip
Site Owner
 
ricktrip's Avatar

Forum Notability:
26 pts: User-friendly
[Post Feedback]
 
Join Date: Oct 2003
Posts: 81
server behavior

I’m looking for suggestions, and I’ll take anything!

I have an html form that lets students check boxes for courses they want to start. it calls a perl script named register.com (on exploringmyself.com). Yes, I’m a high school teacher, not a trained programmer. I often have coding errors that take me a day to figure out, but this one has baffled me for over a week! I’m pretty good at basic perl, but I don’t know beans about Linux or how servers work. Here’s the problem:

I wrote a script that seemed simple to me, but is misbehaving in a way that confuses me. If I check boxes for 5 courses, everything works well and “instantly” — meaning I get a confirmation from the server with a list of courses registered. But if I check 6 or more boxes, the browser hangs and eventually gives up. Meanwhile, the first 5 courses are registered “instantly” then about a minute and a half later the 6th one is registered. Why the delay?

If I am using up a minute and half of server time, that’s HUGE; I’m gonna get in trouble with FutureQuest! But strangely, this only happens to the 6th course — and it doesn’t matter what the 6th course is.

I’ve been a week commenting out sections of code to see what might be hogging time. Unless I’ve blundered (could easily happen), the few offending few lines among the 400+ lines seem to be as follows:

Code:
    open my $fh, '<', "$course_file.txt"
        or die "could not open $course_file.txt: $!";
    while (my $line = <$fh>) {
        chomp $line;
        my ($key, $value) = split /\t/, $line;
        $course_hash{$key} = $value;
   }
    close $fh;
If there’s a problem here, I don’t see it. All the files I read and write are from 1 to maybe 50K; this is not processor intensive! And more importantly, why the hang on only the 6th course??

I’d like to fix what’s wrong, but I haven’t a clue what it is. What does it mean when a server ignores me for a minute and a half then finishes what it started??

Rick Triplett
ricktrip is offline   Reply With Quote
Old 11-06-2018, 12:11 PM   Postid: 186790
Slim
Site Owner
 
Slim's Avatar

Forum Notability:
10 pts: User-friendly
[Post Feedback]
 
Join Date: Nov 2001
Location: Ann Arbor, Michigan
Posts: 182
Re: server behavior

How did you decide that these lines were the offending lines? It's not obvious how they are connected to the selection of check boxes. They are setting up a hash from a file.
Is the file determined by the check boxes? Are the check boxes set up from the file?
Do you have an example of a small file that causes the problem?
Slim is offline   Reply With Quote
Old 11-06-2018, 12:54 PM   Postid: 186791
ricktrip
Site Owner
 
ricktrip's Avatar

Forum Notability:
26 pts: User-friendly
[Post Feedback]
 
Join Date: Oct 2003
Posts: 81
Re: server behavior

The code I previously posted may not be the offending lines; but this is the only part of the code that, when deleted or simplified, made the browser hang go away. The following code is the main part of the program, a foreach loop followed by serving data to the browser.

All files are tab separated key/value pairs that mirror the hashes used in my processing. The html checkboxes send one or more course titles (short scalars) to register.cgi for processing, stored in @course_file_list. I really don’t know what is causing the problem, and I don’t know where to look because I don’t know how to interpret the server’s behavior. There is no help in the server logs. If I knew more about programming, I would add code that would step through its tasks gradually, recording data about what was going on; but this may be beyond me.

At present I am just asking for suggestions on what sorts of things could make a server behave this way, so I could have at least some clue about what to look for in my code.

Code:
# Remaining parts of %pf will change for each course_file registration:
foreach my $course_file (@course_file_list){

    # maybe this course has already been registered
    if ( already_exists($course_file) ){
        $reg_exists .= display($course_file);
        next;   # Skip to next $course_file if any
    }

    # try to get 3 data for this progress file and count them
    my $assignments = (
        ( $pf{n_max}, 
          $pf{course_name}, 
          $pf{effort_report_list}
        ) = course_found($course_file)
     );
    if ( $assignments != 3 ){   # flag and skip if assignment failed

        $reg_unknown  .= display($course_file);
        next;   # Skip to next $course_file if any
    }

    # things are looking good, so write this progress file
    if ( write_progress_file($course_file) ){    # successful write
        $reg_yes .= display($course_file); 
        next;   # Skip to next $course_file if any
    }
    else {                                       # unsuccessful write
        $reg_no .= display($course_file);
        next;   # Skip to next $course_file if any
    }
}

# serve registration statuses to browser
report_registrations( $reg_exists,
                      $reg_unknown, 
                      $reg_yes, 
                      $reg_no, 
                    );

exit;
ricktrip is offline   Reply With Quote
Old 11-08-2018, 11:05 AM   Postid: 186794
Slim
Site Owner
 
Slim's Avatar

Forum Notability:
10 pts: User-friendly
[Post Feedback]
 
Join Date: Nov 2001
Location: Ann Arbor, Michigan
Posts: 182
Re: server behavior

It's hard to place together what you are doing to make a good guess. What could slow down a server this way? A minute and a half?

Filling memory so you start swapping out? Even there, a minute and a half is a long time.
Or there could be a sleep() somewhere in the code.

Perhaps it would be worthwhile getting the time() at different points in the program and print a report of that to a file? That would tell you where the time is being spent.

Perhaps even better would be to run the program from the command line rather than through a browser. You can feed the inputs in as if they were from the browser, see
https://www.perlmonks.org/?node_id=203832
Slim is offline   Reply With Quote
Old 11-10-2018, 07:40 AM   Postid: 186799
ricktrip
Site Owner
 
ricktrip's Avatar

Forum Notability:
26 pts: User-friendly
[Post Feedback]
 
Join Date: Oct 2003
Posts: 81
Re: server behavior

Thank you, Slim, for your helpful comments. I think your idea about coding in some timing is especially useful, and I look forward to playing with it!
ricktrip is offline   Reply With Quote
Old 11-14-2018, 09:21 AM   Postid: 186842
kitchin
Site Owner

Forum Notability:
1202 pts: A True Crowd-pleaser!
[Post Feedback]
 
Join Date: Jan 2001
Location: Virginia
Posts: 3,021
Re: server behavior

Make sure the subs are not modifying @course_file_list in that loop? Debug with print statements inside the loops.

Style-wise, I would eliminate the else-after-next situations, just for clarity. You could delete the 2nd and 3rd "next" lines.

And of course don't trust the input. Checkbox value only allowed if it matches values from a known list or matches a very specific pattern.
kitchin is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 visitors)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 12:22 AM.


Running on vBulletin®
Copyright © 2000 - 2019, Jelsoft Enterprises Ltd.
Hosted & Administrated by FutureQuest, Inc.
Images & content copyright © 1998-2019 FutureQuest, Inc.
FutureQuest, Inc.