ruby-lsapi 2.3 → 2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README +13 -0
  2. data/ext/lsapi/lsapilib.c +67 -21
  3. metadata +2 -2
data/README CHANGED
@@ -74,24 +74,35 @@ Usually, there is no need to set value of LSAPI_CHILDREN over 100 in most
74
74
  server environment.
75
75
 
76
76
 
77
+ * LSAPI_EXTRA_CHILDREN (default: 1/2 of LSAPI_CHILDREN)
78
+
79
+ LSAPI_EXTRA_CHILDREN controls the maximum number of extra children processes
80
+ can be started when some or all existing children processes are in
81
+ malfunctioning state. Total number of children processes will be reduced to
82
+ LSAPI_CHILDREN level as soon as service is back to normal.
83
+
84
+
77
85
  * LSAPI_MAX_REQUESTS (default value: 10000)
78
86
 
79
87
  LSAPI_MAX_REQUESTS specifies the maximum number of requests each child
80
88
  process will handle before it exits automatically. This parameter can
81
89
  help reducing memory usage when there are memory leaks in the application.
82
90
 
91
+
83
92
  * LSAPI_MAX_IDLE (default value: 300 seconds)
84
93
 
85
94
  In Self Managed Mode, LSAPI_MAX_IDLE controls how long a idle child
86
95
  process will wait for a new request before exit. This option help
87
96
  releasing system resources taken by idle processes.
88
97
 
98
+
89
99
  * LSAPI_MAX_IDLE_CHILDREN (default value: 1/3 of LSAPI_CHILDREN)
90
100
 
91
101
  In Self Managed Mode, LSAI_MAX_IDLE_CHILDREN controls how many idle
92
102
  children processes are allowed. Excessive idle children processes
93
103
  will be killed by the parent process.
94
104
 
105
+
95
106
  * LSAPI_MAX_PROCESS_TIME (default value: 300 seconds)
96
107
 
97
108
  In Self Managed Mode, LSAPI_MAX_PROCESS_TIME controls the maximum
@@ -100,6 +111,7 @@ can not finish processing of a request in the given time period, it
100
111
  will be killed by the parent process. This option can help getting rid
101
112
  of dead or runaway child process.
102
113
 
114
+
103
115
  * LSAPI_PGRP_MAX_IDLE (default value: FOREVER )
104
116
 
105
117
  In Self Managed Mode, LSAPI_PGRP_MAX_IDLE controls how long the parent
@@ -107,6 +119,7 @@ process will wait before exiting when there is no child process.
107
119
  This option help releasing system resources taken by an idle parent
108
120
  process.
109
121
 
122
+
110
123
  * LSAPI_PPID_NO_CHECK
111
124
 
112
125
  By default a LSAPI application check the existence of its parent process
@@ -1465,6 +1465,7 @@ typedef struct _lsapi_prefork_server
1465
1465
  {
1466
1466
  int m_fd;
1467
1467
  int m_iMaxChildren;
1468
+ int m_iExtraChildren;
1468
1469
  int m_iCurChildren;
1469
1470
  int m_iMaxIdleChildren;
1470
1471
  int m_iServerMaxIdle;
@@ -1496,6 +1497,7 @@ int LSAPI_Init_Prefork_Server( int max_children, fn_select_t fp )
1496
1497
 
1497
1498
  s_ppid = getppid();
1498
1499
  g_prefork_server->m_iMaxChildren = max_children;
1500
+ g_prefork_server->m_iExtraChildren = max_children / 2 ;
1499
1501
  g_prefork_server->m_iMaxIdleChildren = max_children / 3;
1500
1502
  g_prefork_server->m_iChildrenMaxIdleTime = 30;
1501
1503
  g_prefork_server->m_iMaxReqProcessTime = 300;
@@ -1597,11 +1599,11 @@ static int lsapi_init_children_status()
1597
1599
  return 0;
1598
1600
  }
1599
1601
 
1600
- static void lsapi_check_child_status()
1602
+ static void lsapi_check_child_status( long tmCur )
1601
1603
  {
1602
1604
  int idle = 0;
1603
1605
  int tobekilled;
1604
- long tmCur = time( NULL );
1606
+ int dying = 0;
1605
1607
  lsapi_child_status * pStatus = g_prefork_server->m_pChildrenStatus;
1606
1608
  lsapi_child_status * pEnd = g_prefork_server->m_pChildrenStatus + g_prefork_server->m_iMaxChildren * 2;
1607
1609
  while( pStatus < pEnd )
@@ -1613,7 +1615,9 @@ static void lsapi_check_child_status()
1613
1615
  {
1614
1616
  if ( !pStatus->m_inProcess )
1615
1617
  {
1616
- if ( idle > g_prefork_server->m_iMaxIdleChildren )
1618
+
1619
+ if (( g_prefork_server->m_iCurChildren - dying > g_prefork_server->m_iMaxChildren)||
1620
+ ( idle > g_prefork_server->m_iMaxIdleChildren ))
1617
1621
  {
1618
1622
  tobekilled = 1;
1619
1623
  }
@@ -1643,13 +1647,34 @@ static void lsapi_check_child_status()
1643
1647
  if ( tobekilled )
1644
1648
  kill( pStatus->m_pid, tobekilled );
1645
1649
  ++pStatus->m_iKillSent;
1650
+ ++dying;
1646
1651
  }
1647
1652
 
1648
1653
  }
1654
+ else
1655
+ ++dying;
1649
1656
  ++pStatus;
1650
1657
  }
1651
1658
  }
1652
1659
 
1660
+ static int lsapi_all_children_must_die()
1661
+ {
1662
+ int maxWait;
1663
+ int sec =0;
1664
+ g_prefork_server->m_iMaxReqProcessTime = 10;
1665
+ g_prefork_server->m_iMaxIdleChildren = -1;
1666
+ maxWait = 15;
1667
+
1668
+ while( g_prefork_server->m_iCurChildren && (sec < maxWait) )
1669
+ {
1670
+ lsapi_check_child_status(time(NULL));
1671
+ sec++;
1672
+ }
1673
+ if ( g_prefork_server->m_iCurChildren != 0 )
1674
+ kill( -getpgrp(), SIGKILL );
1675
+ return 0;
1676
+ }
1677
+
1653
1678
 
1654
1679
 
1655
1680
  static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer, LSAPI_Request * pReq )
@@ -1658,8 +1683,9 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer, LSAPI_Re
1658
1683
  old_usr1, old_child;
1659
1684
  lsapi_child_status * child_status;
1660
1685
  int wait_secs = 0;
1661
- int ret;
1686
+ int ret = 0;
1662
1687
  int pid;
1688
+ time_t lastTime = 0, curTime;
1663
1689
  fd_set readfds;
1664
1690
  struct timeval timeout;
1665
1691
 
@@ -1689,9 +1715,33 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer, LSAPI_Re
1689
1715
  s_stop = 0;
1690
1716
  while( !s_stop )
1691
1717
  {
1692
- if ( pServer->m_iCurChildren >= (pServer->m_iMaxChildren << 1 ) )
1718
+ if ( ret )
1719
+ curTime = time( NULL );
1720
+ else
1721
+ ++curTime;
1722
+ if (curTime != lastTime )
1723
+ {
1724
+ lastTime = curTime;
1725
+ if (s_ppid &&
1726
+ (kill(s_ppid, 0) == -1)&&(errno == ESRCH))
1727
+ break;
1728
+ lsapi_check_child_status(curTime );
1729
+ if (pServer->m_iServerMaxIdle)
1730
+ {
1731
+ if ( pServer->m_iCurChildren <= 0 )
1732
+ {
1733
+ ++wait_secs;
1734
+ if ( wait_secs > pServer->m_iServerMaxIdle )
1735
+ return -1;
1736
+ }
1737
+ else
1738
+ wait_secs = 0;
1739
+ }
1740
+ }
1741
+
1742
+ if ( pServer->m_iCurChildren >= (pServer->m_iMaxChildren + pServer->m_iExtraChildren ) )
1693
1743
  {
1694
- usleep( 10000 );
1744
+ usleep( 100000 );
1695
1745
  continue;
1696
1746
  }
1697
1747
 
@@ -1719,21 +1769,6 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer, LSAPI_Re
1719
1769
  }
1720
1770
  else
1721
1771
  {
1722
- if (s_ppid &&
1723
- (kill(s_ppid, 0) == -1)&&(errno == ESRCH))
1724
- break;
1725
- lsapi_check_child_status();
1726
- if (pServer->m_iServerMaxIdle)
1727
- {
1728
- if ( pServer->m_iCurChildren <= 0 )
1729
- {
1730
- ++wait_secs;
1731
- if ( wait_secs > pServer->m_iServerMaxIdle )
1732
- return -1;
1733
- }
1734
- else
1735
- wait_secs = 0;
1736
- }
1737
1772
  continue;
1738
1773
  }
1739
1774
 
@@ -1785,6 +1820,7 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer, LSAPI_Re
1785
1820
  }
1786
1821
  sigaction( SIGUSR1, &old_usr1, 0 );
1787
1822
  kill( -getpgrp(), SIGUSR1 );
1823
+ lsapi_all_children_must_die(); // Sorry, children ;-)
1788
1824
  return -1;
1789
1825
 
1790
1826
  }
@@ -1900,6 +1936,12 @@ void LSAPI_Set_Max_Children( int maxChildren )
1900
1936
  g_prefork_server->m_iMaxChildren = maxChildren;
1901
1937
  }
1902
1938
 
1939
+ void LSAPI_Set_Extra_Children( int extraChildren )
1940
+ {
1941
+ if (( g_prefork_server )&&( extraChildren >= 0 ))
1942
+ g_prefork_server->m_iExtraChildren = extraChildren;
1943
+ }
1944
+
1903
1945
  void LSAPI_Set_Max_Process_Time( int secs )
1904
1946
  {
1905
1947
  if (( g_prefork_server )&&( secs > 0 ))
@@ -1978,6 +2020,10 @@ void LSAPI_Init_Env_Parameters( fn_select_t fp )
1978
2020
  LSAPI_Set_Server_fd( g_req.m_fdListen );
1979
2021
  }
1980
2022
 
2023
+ p = getenv( "LSAPI_EXTRA_CHILDREN" );
2024
+ if ( p )
2025
+ LSAPI_Set_Extra_Children( atoi( p ) );
2026
+
1981
2027
  p = getenv( "LSAPI_MAX_IDLE_CHILDREN" );
1982
2028
  if ( p )
1983
2029
  LSAPI_Set_Max_Idle_Children( atoi( p ) );
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: ruby-lsapi
5
5
  version: !ruby/object:Gem::Version
6
- version: "2.3"
7
- date: 2007-03-15 00:00:00 -05:00
6
+ version: "2.4"
7
+ date: 2007-04-24 00:00:00 -04:00
8
8
  summary: A ruby extension for fast communication with LiteSpeed Web Server.
9
9
  require_paths:
10
10
  - lib