• Welcome to OS2World OLD-STATIC-BACKUP Forum.
 

News:

This is an old OS2World backup forum for reference only. IT IS READ ONLY!!!

If you need help with OS/2 - eComStation visit http://www.os2world.com/forum

Main Menu

(Apache/PHP/MySQL related) Looking for info on PROCESSES= config.sys statement

Started by RobertM, 2010.04.12, 21:45:07

Previous topic - Next topic

RobertM

I've had a few more ideas...

I can monitor MySQL's load and look for times it isn't in use before calling a shutdown (and if it is in use, and memory is running out and it still is in use while exceeding x number of seconds/minutes force a shutdown anyway).

And may be able to do that with Apache as well (not sure... gotta test some things).

I've got some testing with RXU to do...


|
|
Kirk's 5 Year Mission Continues at:
Star Trek New Voyages
|
|


RobertM

Here's the simple and somewhat error prone version of the script. The comments and notes in it say it all - but it does generally serve it's purpose.

If and when I finish fine tuning it, I will post a new one.


/* Start and Control MySQL and Apache */


/*
    THIS SCRIPT IS IN MY C:\Scripts Directory
    You must modify the 3rd to last line (in the main section of this script) to the location you place it on your system


    Currently, this script does NO checking to see if it actually succeeds in trying to kill
    either Apache or MySQL. If it fails, it will still try to spawn new copies.
*/


    /* Define Daemon Locations */
        ApacheDir='D:\SERVERDAEMONS\APACHE2\'           /* DONT FORGET TRAILING SLASH */
        MySQLDir="D:\SERVERDAEMONS\MYSQL5\BIN\"         /* DONT FORGET TRAILING SLASH */
        ApacheLogsDir="D:\serverdaemons\apache2\logs\"  /* DONT FORGET TRAILING SLASH */
            /* This entry is where httpd.pid will be located */

    /* Define wait time before killing and restarting MySQL and Apache */
        xHours=3

    /* SLEEP for 3 seconds to allow killing of the script if need be */
        rtc=SysSleep(3)



    /* Detach and Run MySQL */
    /*
        REMOVE any parameters in the "start... MySQLD.EXE" line below that you do not use:
        I am simply too lazy to change my my.cnf file while I am testing what works on my system
    */

        'start /c /b /min 'MySQLDir'MYSQLD.EXE --max_seeks_for_key=50 --max_connections=500 --bulk_insert_buffer_size=64M --key_buffer_size=96M --table_cache=128 --sort_buffer_size=32M --read_buffer_size=8M'


    /* Detach and Run Apache */

        'start "Apache" /c /b /min D:\SERVERDAEMONS\APACHE2\STARTUP.CMD'


    /* Wait xHours until kill and restart of services */
        Say "Waiting "xHours" hours from: "Time()
        SleepTime=60*60*xHours

        rtc=SysSleep(SleepTime)


    /* Request proper shutdown of MySQL and Apache */
        'mysqladmin shutdown'
        rtc=Kill_Apache()

        /*
            BOTH of these are called WITHIN this REXX procedure and MUST be called from it
            - If you try to detach these, then if there is a problem (out of resources) the
              detached processes will NOT be started and the resources will not be freed.

              Inotherwords, nothing will happen at all except this will exit with two out of
              resources errors and the server daemons will not be restarted.

            - I have moved the Apache "Shutdown" script into this as a "function"
              You need to ensure that KILL is available in your path statement
              - Inotherwords, you need to add an entry to the config.sys path statement
                or ensure you have placed KILL.EXE in an already defined locations such as
                \OS2\BIN
        */


    /*
        Assumes both services have been killed.
        At this point, to ensure all resources are freed (including those used by this script)
        we will spawn another copy of this script which will wait 3 seconds (as defined above)
        before restarting the services in their own process spaces.

        This script will then exit 3 seconds later to free any resources it is using.

        While this script should not be using much in the line of resources, I have found that
        on ObjectREXX (especially the version shipped with eCS 1.2MR) every REXX script seems to
        leak resources the longer it runs.

        Thus, killing and restarting this script, instead of just looping forever, will alleviate
        those ObjectREXX issues.
    */


    /* Time to restart this script in a new session and then exit and close this session */
        'start /c /b /min C:\SCRIPTS\Run_ApacheMysql.cmd'
        /*
            You may wish to remove "/min" from the above to allow you to easily find and kill this
            script in the 3 second window it gives you in the event it gets stuck in a restart loop.
           
            While that shouldnt happen, it's just a thought.
           
            To properly kill things if a loop occurs or there is another problem, find and kill THIS
            script first, then properly shut down MySQL and kill Apache - then restart this script.
        */


        rtc=SysSleep(3)


Return 0            /* This script exits here */





Kill_Apache:
    pid = linein(ApacheLogsDir"httpd.pid")
    'kill.exe -TERM 'pid
Return 0


|
|
Kirk's 5 Year Mission Continues at:
Star Trek New Voyages
|
|


RobertM

A final note to those of you running into single requests that are eating all available resources... by tweaking the PHP.ini, httpd.conf and my.cnf files, you should be able to avoid that to some extent.

While doing so may decrease performance of some queries, it will increase uptime by not causing anything to hang due to lack of resources.

The way the script is currently written, it should mean that there should be no more than xHours (see script - currently defined as 3 hours) worth of downtime at any given cycle (because at xHours, both MySQL and Apache will be shut down and restarted, which will free up any resources).


|
|
Kirk's 5 Year Mission Continues at:
Star Trek New Voyages
|
|


Fahrvenugen

Thanks!

While that doesn't solve the memory / lockup problems, it does likely provide a work-around.  I'll have to give it a try.

RobertM

Quote from: Fahrvenugen on 2010.05.10, 16:20:38
Thanks!

While that doesn't solve the memory / lockup problems, it does likely provide a work-around.  I'll have to give it a try.


I'm looking into some of the other ideas others have posted... such as trying to force an unload of libc063 (which definitely seems to be the problems according to Apache's error logs), and trying to re-align memory use to create contiguous free memory blocks.

I'm also working on integrating the use of RXU to monitor free memory space to cause an "unscheduled" shutdown and restart of Apache and MySQL if free memory drops below a certain user defined threshold.

Also, in my script, there is one line that is in error (or needs to be custom set)


    'start "Apache" /c /b /min D:\SERVERDAEMONS\APACHE2\STARTUP.CMD'



It should have read:


    'start "Apache" /c /b /min 'ApacheDir'STARTUP.CMD'


Of course, manually changing it to the correct path would work as well, but changing it to use the pre-defined variable at the top of the script makes it a lot easier to maintain if one decides to move their Apache installation to another path/drive - just then requires updating the variable definition at the top of the script.


|
|
Kirk's 5 Year Mission Continues at:
Star Trek New Voyages
|
|


RobertM

Quote from: mobybrick on 2010.04.25, 01:50:09
2. Building apps with static linking under GCC - reducing reliance on a shared DLL in memory. Whether or not this is feasible I don't know - but it would appear to solve other problems IMHO.

Regards,
Moby

Moby, do you think simply number 2 would alleviate these issues? I've gotten some info from RXU and am seeing the following:

After a few hours of running:
- Free Shared Memory: 44MB
- Free Memory in Private Arena that the process can allocate: 291MB

After shutting down services:
- Free Shared Memory: 245MB
- Free Memory in Private Arena that the process can allocate: 291MB

After restarting services:
- Free Shared Memory: 223MB
- Free Memory in Private Arena that the process can allocate: 291MB


The key being it seems that the private arena has a big chunk of available memory - currently more so than the shared arena starts with. If each (PHP, MySQL and Apache) had LIBC063 functionality statically linked, would that mean that EACH would have that 291MB available to it?

I am also suspecting that on most systems, the amount will be more... as I am allocating a bit of memory for JFS cache and such.


|
|
Kirk's 5 Year Mission Continues at:
Star Trek New Voyages
|
|


mobybrick

Yes, it should. But why static linking is not used, I do not know. If this was an pure OS/2 library then it would and OS/2 provides a static facility. The size of the program executables would grow (and overall, memory consumption would increase) and how items such as libc_sharedmem would work would need effort.

KLIBC needs a bit of an update IMHO, to fix some of the long-outstanding bugs and to work on the memory and pthreads situation.

Regards,
Moby.

Quote from: RobertM on 2010.05.10, 20:48:06
Quote from: mobybrick on 2010.04.25, 01:50:09
2. Building apps with static linking under GCC - reducing reliance on a shared DLL in memory. Whether or not this is feasible I don't know - but it would appear to solve other problems IMHO.

Regards,
Moby

Moby, do you think simply number 2 would alleviate these issues? I've gotten some info from RXU and am seeing the following:

After a few hours of running:
- Free Shared Memory: 44MB
- Free Memory in Private Arena that the process can allocate: 291MB

After shutting down services:
- Free Shared Memory: 245MB
- Free Memory in Private Arena that the process can allocate: 291MB

After restarting services:
- Free Shared Memory: 223MB
- Free Memory in Private Arena that the process can allocate: 291MB


The key being it seems that the private arena has a big chunk of available memory - currently more so than the shared arena starts with. If each (PHP, MySQL and Apache) had LIBC063 functionality statically linked, would that mean that EACH would have that 291MB available to it?

I am also suspecting that on most systems, the amount will be more... as I am allocating a bit of memory for JFS cache and such.

RobertM

NOTE 05/18/2010 @ 13:28EDT:
I have modified the script a little... I have now added the force shutdown and shutdown parameter to the MySQLAdmin shutdown statement to ensure that control from MySQLAdmin returns on completion.

I have also preceded all the other cmdline calls with the "@" symbol so they aren't echo'd to the console window.



Hey all,

Sorry this took so long for a very minor (programming wise) update, but here is the revised script including use of RXU to address low memory issues.

NOTES NOT IN THE SCRIPT:
- You MUST have RXU installed (find it on Hobbes, grab most recent version)
- You MUST either:
  (a) have it loaded and available via another script (I load all my REXX dlls via one script on system start) OR
  (b) add the code to load it into this script (standard method to load the REXX DLL functions, see RXU's documentation)

- This script will automatically shut down and restart MySQL and Apache in x number of hours (see notes in script)

- This script will check/monitor free shared memory space every 5 seconds and upon reaching y threshold, kill and restart MySQL and Apache.

- Hours before restart and minimum free memory before untimed restart are defined in script

- Script now shows time before restart (in seconds) as ###Sec Elapsed/###Sec to Restart - once #Sec Elapsed exceeds #Sec Restart, it will trigger a restart

- Script now shows (first line) amount of shared memory available when script was started

- Script now shows percentage remaining of shared memory every 5 seconds. This percentage is based off what was available on script start (it is not based on max available of 512MB). Inotherwords, if this script started with 200MB available in the shared arena, and 100MB of that gets used, it will show 50% free.

- When I get a chance, I will make the display a bit neater, maybe even with a few bar graphs for mem usage and time, and will probably incorporate some routines to query MySQL and Apache for what their current load is. It may be a month before I get around to that though, as I am deep into helping plan the next Star Trek Phase 2 Shoot, and once I finish the planning work, will be away at the shoot until the third week in June.


/* Start and Control MySQL and Apache */
/*
    THIS SCRIPT IS IN MY C:\Scripts Directory
    You must modify this line to the location you place it on your system
*/
    ThisDir="C:\Scripts\"



/*
    Currently, this script does NO checking to see if it actually succeeds in trying to kill
    either Apache or MySQL. If it fails, it will still try to spawn new copies.
*/
    '@mode 80,8'

    rtc=SysCurState("OFF")
    dosrc = RxQuerySysInfo( 'RxSysInfoOrig.' )

    /* Define Daemon Locations */
        ApacheDir='D:\SERVERDAEMONS\APACHE2\'           /* DONT FORGET TRAILING SLASH */
        MySQLDir="D:\SERVERDAEMONS\MYSQL5\BIN\"         /* DONT FORGET TRAILING SLASH */
        ApacheLogsDir="D:\serverdaemons\apache2\logs\"  /* DONT FORGET TRAILING SLASH */
            /* This entry is where httpd.pid will be located */

    /* Define wait time before killing and restarting MySQL and Apache */
        xHours=3

    /* Define Minimum Avail Shared Memory Space */
        memMinimum=60000000

    /* SLEEP for 3 seconds to allow killing of the script if need be */
    /*
        rtc=SysSleep(3)
    */



    /* Detach and Run MySQL */
    /*
        REMOVE any parameters in the "start... MySQLD.EXE" line below that you do not use:
        I am simply too lazy to change my my.cnf file while I am testing what works on my system
    */
        '@start "MySQL Daemon" /c /b /min 'MySQLDir'MYSQLD.EXE --max_seeks_for_key=50 --max_connections=500 --bulk_insert_buffer_size=32M --key_buffer_size=48M --table_cache=128 --sort_buffer_size=16M --read_buffer_size=8M'

        rtc=SysCurPos(5,0)
        Say Left("-STARTED: MySQL Daemon",79)


    /* Detach and Run Apache */

        '@start "Apache" /c /b /min 'ApacheDir'STARTUP.CMD'
        rtc=SysCurPos(6,0)
        Say Left("-STARTED: Apache Daemon",79)


    /* Wait xHours until kill and restart of services */
        rtc=SysCurPos(0,0)
        Say "Waiting "xHours" hours from: "Time()"   Started with "RxSysInfoOrig.21" bytes free memory"
        SleepTime=60*60*xHours

        cSleep=0
        Do Forever
            rtc=SysSleep(5)
            cSleep=cSleep+5
            dosrc = RxQuerySysInfo( 'RxSysInfo.' )
            if RxSysInfo.M<memMinimum Then
            Do
                rtc=SysCurPos(2,0)
                Say Left("-WARNING: Memory Threshold Met ("RxSysInfo.21<memMinimum")",79," ")
                rtc=Beep(349,10)
                Leave
            End

            rtc=SysCurPos(1,0)
            Say Left("-Reset Timer: "Right(cSleep||"/"||SleepTime,Length(SleepTime)*2+4)" seconds. ",79," ")
            rtc=SysCurPos(2,0)
            Say Left("-Free memory: "RxSysInfo.21" bytes    ("Format((RxSysInfo.21/RxSysInfoOrig.21)*100,3,1)"% free)",79," ")



            If cSleep=35 Then
            Do
                rtc=SysCurPos(6,0)
                Say Left(" ",79)

            End

            If cSleep=30 Then
            Do
                rtc=SysCurPos(5,0)
                Say Left(" ",79)

            End

            If cSleep>SleepTime Then
            Do
                Leave
            End


        End


    /* Request proper shutdown of MySQL and Apache */

        rtc=Kill_Apache()
        rtc=Kill_MySQL()

        /*
            BOTH of these are called WITHIN this REXX procedure and MUST be called from it
            - If you try to detach these, then if there is a problem (out of resources) the
              detached processes will NOT be started and the resources will not be freed.

              Inotherwords, nothing will happen at all except this will exit with two out of
              resources errors and the server daemons will not be restarted.

            - I have moved the Apache "Shutdown" script into this as a "function"
              You need to ensure that KILL is available in your path statement
              - Inotherwords, you need to add an entry to the config.sys path statement
                or ensure you have placed KILL.EXE in an already defined locations such as
                \OS2\BIN
        */


    /*
        Assumes both services have been killed.
        At this point, to ensure all resources are freed (including those used by this script)
        we will spawn another copy of this script which will wait 3 seconds (as defined above)
        before restarting the services in their own process spaces.

        This script will then exit 3 seconds later to free any resources it is using.

        While this script should not be using much in the line of resources, I have found that
        on ObjectREXX (especially the version shipped with eCS 1.2MR) every REXX script seems to
        leak resources the longer it runs.

        Thus, killing and restarting this script, instead of just looping forever, will alleviate
        those ObjectREXX issues.
    */




    /* Time to restart this script in a new session and then exit and close this session */
        rtc=Restart_AM()
        /*
            You may wish to remove "/min" from the above to allow you to easily find and kill this
            script in the 3 second window it gives you in the event it gets stuck in a restart loop.

            While that shouldnt happen, it's just a thought.

            To properly kill things if a loop occurs or there is another problem, find and kill THIS
            script first, then properly shut down MySQL and kill Apache - then restart this script.
        */


        /*
        rtc=SysSleep(3)
        */

Exit
            /* This script exits here */





Kill_Apache:
    pid = linein(ApacheLogsDir"httpd.pid")
    '@kill.exe -TERM 'pid
Return 0


Kill_MySQL:
    '@mysqladmin shutdown --force --shutdown_timeout=30'
Return 0


Restart_AM:
    '@start /c /b 'ThisDir'Run_ApacheMysql.cmd'
Return 0




|
|
Kirk's 5 Year Mission Continues at:
Star Trek New Voyages
|
|


RobertM

Still needed:
-Error checking (especially to ensure initial values are not too low... (such as in my case if I were to set the memory restart trigger at 300MB, when the system only has 280MB free after boot and loading of the support DLLs and firewall)).

-Fancier interface

-More information on the interface

-Perhaps more detailed information on both daemons and/or on the TCP/IP stack itself
(that may come in handy if you have a server that gets attacked or flooded from time to time - we had such an attempt yesterday where one IP continued to open (and hold open) as many http requests as possible - for some reason, Apache didnt do anything about it, though I am sure I have a per client connection limit in place - or am misreading the setting in the config file).

-"Theoretically" (ie: when I get around to it), the script can automagically add such IP entries to the firewall, force the firewall to reload it's rules and create a log for review.


|
|
Kirk's 5 Year Mission Continues at:
Star Trek New Voyages
|
|


RobertM

Hi all,

I HOPE to have some very good news regarding this problem, very soon.

First, don't thank me: I will just be the messenger - all the work involved is being done by someone else. I'll let you know how things go once we do some testing. If all works out, (assuming the person doesnt post something about this before then), I'll let you all know who we have to thank for it.

Best,
Robert


|
|
Kirk's 5 Year Mission Continues at:
Star Trek New Voyages
|
|


Fahrvenugen

Quote from: RobertM on 2010.07.09, 06:31:08
Hi all,

I HOPE to have some very good news regarding this problem, very soon.
....


Could this be the elusive static-linking to fix lots of memory issues problem being finally solved?  Or an update to your shutdown/restart script?

If its the static linking, that would be fantastic!  Not to say the shutdown / restart script doesn't help, but it is still a work-around for the real issue.


RobertM

Quote from: Fahrvenugen on 2010.07.10, 18:32:54
Quote from: RobertM on 2010.07.09, 06:31:08
Hi all,

I HOPE to have some very good news regarding this problem, very soon.
....


Could this be the elusive static-linking to fix lots of memory issues problem being finally solved?  Or an update to your shutdown/restart script?

If its the static linking, that would be fantastic!  Not to say the shutdown / restart script doesn't help, but it is still a work-around for the real issue.



LIBC063 apparently already supports using high memory - IF the apps that call it are compiled to request it for their shared memory space.  :)

MySQL and PHP (most recent version, at the least) are already compiled to request high memory...  :)
- Make sure you've upgraded your PHP and modPHP stuff in the Apache modules directory

Now, Apache on the other hand...


|
|
Kirk's 5 Year Mission Continues at:
Star Trek New Voyages
|
|


RobertM

Quote from: Fahrvenugen on 2010.07.10, 18:32:54

If its the static linking, that would be fantastic!  Not to say the shutdown / restart script doesn't help, but it is still a work-around for the real issue.



Things are looking VERY VERY good so far... and very snappy too! I think by Monday, I will have something very decent to post.


|
|
Kirk's 5 Year Mission Continues at:
Star Trek New Voyages
|
|


Fahrvenugen

I'm anxiously awaiting Monday!

That does sound promising though.  I might be able to move my most troublesome website running - currently running on an XP box with Apache / PHP / MySQL (and that's the only thing running on that box, and it only has 1 website on it, so essentially its a dedicated machine type of thing currently) back to an OS/2 platform!

And why is it troublesome?  Because its running on the multi-user version of Wordpress (even though we havn't really used the multi-user thing yet) and there's something in one of its PHP scripts that every so often grabs huge amounts of shared memory and was causing my OS/2 server to crash frequently. I had to get it off that server, and decided to try it on an XP  machine at the time.


RobertM

Hey gang,

So far, everything looks wonderful! Our benefactor in this endeavor is (for those who havent guessed) Paul Smedley! (Thanks Paul!!!)

For those of you wanting to test this, here's the link to the new build and everything else you need:



If you'd like to test it:
If you DONT have Apache v2.2.15 already installed, grab this package:

   *  http://smedley.info/httpd-2.2.15-os2-20100711.zip

IF you are upgrading from an older version of Apache, then make sure you back up your config files first, as xcopying the files over an existing installation will overwrite them.

If you DO have v2.2.15 installed, you can either replace it with the package above, or download this from Paul's site and copy the files in the zip file into your Apache\bin directory.

   * http://download.smedley.info/httpd-testfix-20100710.zip

   - Changes are in the readme

Be sure you have updated MySQL and PHP with these versions:

   * MySQL:
     http://os2ports.smedley.info/index.php?page=mysql-5-1

     (besides LIBC063, it also requires GCC444, located here:
         o http://os2ports.smedley.info/index.php?page=gcc44

   * PHP:
     http://os2ports.smedley.info/index.php?page=php-5

Copy the modphp.dll file in the PHP5\apache directory into Apache's modules directory, and ensure there are no other copies of older versions of modphp.dll or PHP/Apache/MySQL anywhere referenced in your path statements.

That should be it!

The only odd thing I have run in to is that I cannot start MySQL and Apache at the "same" time - I'm still running my little memory monitoring script (though it's set for 24 hours now), and all I had to do was add a one second pause between starting MySQL and Apache (possibly because Apache is looking for/loading some SQL service/dll that isnt yet initialized or is locked during MySQL's startup? Not sure why).

Otherwise, all is working flawlessly for me. After daemon initialization, no usage of the LMA at all (even after... 6+ hours of relatively heavy use serving a big SMF forum), no hangs, no delays... and possibly faster performance (the performance is definitely faster, but I am not sure if that's because of the high memory changes to Apache, or because v2.2.15 is simply faster than the older v2.2.8 I had been running).

Thanks again Paul!

Best,
Robert


|
|
Kirk's 5 Year Mission Continues at:
Star Trek New Voyages
|
|