This little script is able to get my server load to say 69.62. Then once it stops running after like five minutes, it goes back down to about 1. All this script is supposed to do is check if the user that views the page is the Facebook bot or some one else. When it's some one else it simply redirects you to the video on youtube. When it's Facebook, it gives the Facebook bot the Youtube information needed to post the video on Facebook in the correct embedded format so you get embedded views credited on youtube.
#!/usr/bin/perl use CGI ':standard'; $video = param('video'); use LWP::Simple qw(!head); $url = get ("http://www.domain.org/facebookvideos/$video/"); $url =~ s*<meta property="og:description" content="Text of the talk: +<a href='http://domain.org/general-conference/([^&]+)/([^&]+)/([^&]+) + '>http://domain.org/general-confere...</a> ">*<meta property="og:des +cription" content="Text of the talk: http://domain.org/general-confer +ence/$1/$2/$3" />*g; #$url =~ s*tion\" content\=\"*tion\" content\=\"Want more\?\? http://w +ww.domain2.org/ *g; $url =~ s*og:url" content="http://www.domain2.org/videos/*og:url" cont +ent="http://www.domain2.org/facebook/*g; #$url =~ s*Want more\?\? http://www.domain2.org/ Text*Text*g; #facebookexternalhit or Mozilla if ($ENV{'HTTP_USER_AGENT'} =~ /facebookexternalhit/) { print "Content-Type: text/html\n\n"; print <<EOM; $url EOM } else { print "Location: http://www.youtube.com/watch?v=$video\n\n"; EOM }
generates

top - 23:51:16 up 23:18,  1 user,  load average: 69.62, 36.45, 15.11
Tasks: 134 total,  45 running,  86 sleeping,   0 stopped,   3 zombie
Cpu(s): 99.7%us,  0.3%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:    786432k total,   786432k used,        0k free,        0k buffers
Swap:     4264k total,     4264k used,        0k free,        0k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                     
 1512 site100   19   0 55248  11m 1876 R  3.3  1.5   0:01.39 facebook.cgi                 
 1943 site100   19   0 55248  11m 1876 R  3.3  1.5   0:01.09 facebook.cgi                 
 4018 site100   19   0 55248  11m 1876 R  3.3  1.5   0:01.09 facebook.cgi                 
 4024 site100   19   0 55280  11m 1876 R  3.3  1.5   0:02.78 facebook.cgi                 
 4029 site100   19   0 55248  11m 1876 R  3.3  1.5   0:02.81 facebook.cgi                 
 4034 site100   19   0 55280  11m 1876 R  3.3  1.5   0:02.79 facebook.cgi                 
 4044 site100   19   0 55248  11m 1876 R  3.3  1.5   0:01.09 facebook.cgi                 
 4057 site100   19   0 55280  11m 1876 R  3.3  1.5   0:01.04 facebook.cgi                 
 4060 site100   19   0 55280  11m 1876 R  3.3  1.5   0:01.11 facebook.cgi                 
How do you make the script do what it should do in a second or two instead of it spending five minutes killing the server???

In reply to Script needs major optimizing. by Jesse Smith

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.