Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Aug 2004
    Posts
    368
    Thanks
    10
    Thanked 4 Times in 4 Posts

    Run One Instance Of Perl Script At A Time

    I have an online graphics script that receives heavy traffic. Sometimes several visitors are running the script at the same time, and this crashes my Unix server. I need to modify the script so that only one instance can run, and keep the other instances on hold until the first is finished. I have done some research, and most are using file locking. I don't think I need to lock the file. I need to lock the whole script. And, if I lock the script from the other users, will that terminate their input?

    I have some ideas. Please tell me if this would be efficient.

    Each time the script is run, store the input from each user in a text file on a separate line. The script would then read the data from the first line and run the graphics routine. At the end of the script it would delete current line, and then run the script again from the next line of input until all input is exhausted.

    If you have a more efficient way (and I'm sure you do), please advise.

    Thanks in advance!
    Last edited by netroact; 07-17-2014 at 02:31 AM.

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,879
    Thanks
    2
    Thanked 164 Times in 159 Posts
    If this was a console app, then what you're wanting to do would be fairly easy to setup and somewhat common. However, doing this with a web app doesn't make any sense and would be weird and inefficient.

    I'd suggest reworking your script so that it can handle multiple executions at the same time.
    Last edited by FishMonger; 07-19-2014 at 01:49 AM.

  • #3
    Regular Coder
    Join Date
    Aug 2004
    Posts
    368
    Thanks
    10
    Thanked 4 Times in 4 Posts
    Thanks for the reply.

    I didn't mention in my original post that each time the script runs, it takes it awhile to generate the final image. Sometimes, it uses up server resources. I was thinking about using the spinner module while the users wait in line.

    Hope this makes sense.

    Thanks

  • #4
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,879
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Have you tried profiling and then optimizing the parts that are slow and/or cpu intensive?

  • Users who have thanked FishMonger for this post:

    netroact (07-19-2014)

  • #5
    Regular Coder
    Join Date
    Aug 2004
    Posts
    368
    Thanks
    10
    Thanked 4 Times in 4 Posts
    I will definitely look into profiling.

    Thanks again.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •