activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r1082625 - in /activemq/activemq-apollo/trunk: apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/ apollo-broker/src/test/scala/org/apache/activemq/apollo/broker/perf/ apollo-util/src/main/scala/org/apache/activemq/apollo/util/
Date Thu, 17 Mar 2011 18:29:31 GMT
Author: chirino
Date: Thu Mar 17 18:29:31 2011
New Revision: 1082625

URL: http://svn.apache.org/viewvc?rev=1082625&view=rev
Log:
Detect and log the ulimit the broker is running with and recommend an increase if it is set
too low.

Removed:
    activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/ProcessSupport.java
Modified:
    activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala
    activemq/activemq-apollo/trunk/apollo-broker/src/test/scala/org/apache/activemq/apollo/broker/perf/BrokerPerfSupport.scala
    activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/FileSupport.scala

Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala?rev=1082625&r1=1082624&r2=1082625&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala
Thu Mar 17 18:29:31 2011
@@ -267,6 +267,8 @@ class Broker() extends BaseService {
       connection_log = Log(log_category.connection.getOrElse(base_category+"connection"))
       console_log = Log(log_category.console.getOrElse(base_category+"console"))
 
+      log_ulimit
+
       if( config.key_storage!=null ) {
         key_storage = new KeyStorage
         key_storage.config = config.key_storage
@@ -351,6 +353,34 @@ class Broker() extends BaseService {
     tracker.callback(on_completed)
   }
 
+  private def log_ulimit = {
+    import ProcessSupport._
+    launch("ulimit", "-n") { case (rc, out, err) =>
+      if( rc==0 ) {
+        try {
+          val limit = new String(out).trim
+          console_log.info("OS is restricting our open file limit to: %s", limit)
+          if( limit!="unlimited" ) {
+            val l = limit.toInt
+
+            var min_limit = 500 // estimate.. perhaps could we do better?
+            config.connectors.foreach { connector=>
+              import OptionSupport._
+              min_limit += connector.connection_limit.getOrElse(10000)
+            }
+
+            if( l < min_limit ) {
+              console_log.warn("Please increase the process file limit using 'ulimit -n %d'
or configure lower the connection limits on the broker connectors.", min_limit)
+            }
+          }
+        } catch {
+          case _ =>
+        }
+      }
+    }
+
+  }
+
   def get_virtual_host(name: AsciiBuffer) = dispatch_queue ! {
     virtual_hosts_by_hostname.getOrElse(name, null)
   }

Modified: activemq/activemq-apollo/trunk/apollo-broker/src/test/scala/org/apache/activemq/apollo/broker/perf/BrokerPerfSupport.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/test/scala/org/apache/activemq/apollo/broker/perf/BrokerPerfSupport.scala?rev=1082625&r1=1082624&r2=1082625&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/test/scala/org/apache/activemq/apollo/broker/perf/BrokerPerfSupport.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/test/scala/org/apache/activemq/apollo/broker/perf/BrokerPerfSupport.scala
Thu Mar 17 18:29:31 2011
@@ -146,7 +146,8 @@ abstract class BrokerPerfSupport extends
       case report_parser(report_header, _, report_mid, _, report_footer) =>
         var notes = System.getProperty("notes")
         if (notes == null) {
-          val version = new String(ProcessSupport.system("git", "rev-list", "--max-count=1",
"HEAD").toByteArray).trim
+          import ProcessSupport._
+          val version = new String(system("git", "rev-list", "--max-count=1", "HEAD")._2).trim
           notes = "commit " + version
         }
 

Modified: activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/FileSupport.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/FileSupport.scala?rev=1082625&r1=1082624&r2=1082625&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/FileSupport.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/FileSupport.scala
Thu Mar 17 18:29:31 2011
@@ -17,6 +17,7 @@
 package org.apache.activemq.apollo.util
 
 import java.io._
+import org.fusesource.hawtdispatch._
 
 object FileSupport {
 
@@ -104,4 +105,95 @@ object FileSupport {
     new String(out.toByteArray, charset)
   }
 
+}
+
+object ProcessSupport {
+  import FileSupport._
+
+  implicit def to_rich_process_builder(self:ProcessBuilder):RichProcessBuilder = new RichProcessBuilder(self)
+
+  case class RichProcessBuilder(self:ProcessBuilder) {
+
+    def start(out:OutputStream=null, err:OutputStream=null, in:InputStream=null) = {
+      self.redirectErrorStream(out == err)
+      val process = self.start
+      if( in!=null ) {
+        ApolloThreadPool.INSTANCE {
+          try {
+            using(process.getOutputStream) { out =>
+              FileSupport.copy(in, out)
+            }
+          } catch {
+            case _ =>
+          }
+        }
+      } else {
+        process.getOutputStream.close
+      }
+
+      if( out!=null ) {
+        ApolloThreadPool.INSTANCE {
+          try {
+            using(process.getInputStream) { in =>
+              FileSupport.copy(in, out)
+            }
+          } catch {
+            case _ =>
+          }
+        }
+      } else {
+        process.getInputStream.close
+      }
+
+      if( err!=null && err!=out ) {
+        ApolloThreadPool.INSTANCE {
+          try {
+            using(process.getErrorStream) { in =>
+              FileSupport.copy(in, err)
+            }
+          } catch {
+            case _ =>
+          }
+        }
+      } else {
+        process.getErrorStream.close
+      }
+      process
+    }
+
+  }
+
+  implicit def to_rich_process(self:Process):RichProcess = new RichProcess(self)
+
+  case class RichProcess(self:Process) {
+    def on_exit(func: (Int)=>Unit) = ApolloThreadPool.INSTANCE {
+      self.waitFor
+      func(self.exitValue)
+    }
+  }
+
+  implicit def to_process_builder(args:Seq[String]):ProcessBuilder = new ProcessBuilder().command(args
: _*)
+
+  def launch(command:String*)(func: (Int, Array[Byte], Array[Byte])=>Unit ):Unit = {
+    val p:ProcessBuilder = command
+    println("launching: "+p)
+    launch(p)(func)
+  }
+  def launch(p:ProcessBuilder, in:InputStream=null)(func: (Int, Array[Byte], Array[Byte])
=> Unit):Unit = {
+    val out = new ByteArrayOutputStream
+    val err = new ByteArrayOutputStream
+    p.start(out, err, in).on_exit { code=>
+      func(code, out.toByteArray, err.toByteArray)
+    }
+  }
+
+  def system(command:String*):(Int, Array[Byte], Array[Byte]) = system(command)
+  def system(p:ProcessBuilder, in:InputStream=null):(Int, Array[Byte], Array[Byte]) = {
+    val out = new ByteArrayOutputStream
+    val err = new ByteArrayOutputStream
+    val process = p.start(out, err, in)
+    process.waitFor
+    (process.exitValue, out.toByteArray, err.toByteArray)
+  }
+
 }
\ No newline at end of file



Mime
View raw message