Title: [627] trunk/rails-integration/src/main/java/org/jruby/webapp: start fewer rails instances before serving.
- Revision
- 627
- Author
- tirsen
- Date
- 2007-06-14 08:48:21 -0400 (Thu, 14 Jun 2007)
Log Message
start fewer rails instances before serving. by default always run the pool manager. make the tasks wait for available rails instances so we can serve requests earlier.
Modified Paths
Diff
Modified: trunk/rails-integration/src/main/java/org/jruby/webapp/FileServlet.java (626 => 627)
--- trunk/rails-integration/src/main/java/org/jruby/webapp/FileServlet.java 2007-06-14 12:47:04 UTC (rev 626)
+++ trunk/rails-integration/src/main/java/org/jruby/webapp/FileServlet.java 2007-06-14 12:48:21 UTC (rev 627)
@@ -64,6 +64,15 @@
if (welcomeFiles == null) welcomeFiles = DEFAULT_WELCOME_FILES;
return welcomeFiles;
}
+
+ protected String resolvePath(String relativePath) {
+ // if it's relative prepend the web apps root, otherwise just use this path
+ if (new File(directory).isAbsolute()) {
+ return directory + relativePath;
+ } else {
+ return rootPath + File.separator + directory + relativePath;
+ }
+ }
/**
* Transfer the file.
@@ -77,13 +86,7 @@
String contextPath = request.getContextPath();
String relativePath = request.getRequestURI().substring(contextPath.length());
- String realPath;
- // if it's relative prepend the web apps root, otherwise just use this path
- if (new File(directory).isAbsolute()) {
- realPath = directory + relativePath;
- } else {
- realPath = rootPath + File.separator + directory + relativePath;
- }
+ String realPath = resolvePath(relativePath);
realPath = realPath.replaceAll("\\\\", "/").replaceAll("//", "/");
// check the file and open it
Modified: trunk/rails-integration/src/main/java/org/jruby/webapp/RailsContextListener.java (626 => 627)
--- trunk/rails-integration/src/main/java/org/jruby/webapp/RailsContextListener.java 2007-06-14 12:47:04 UTC (rev 626)
+++ trunk/rails-integration/src/main/java/org/jruby/webapp/RailsContextListener.java 2007-06-14 12:48:21 UTC (rev 627)
@@ -93,11 +93,11 @@
protected ObjectPool createObjectPool(RailsFactory railsFactory) {
int maxObjects = getIntegerProperty("jruby.pool.maxActive", 4);
int minIdle = getIntegerProperty("jruby.pool.minIdle", 2);
- int checkInterval = getIntegerProperty("jruby.pool.checkInterval", 0); // 1000
+ int checkInterval = getIntegerProperty("jruby.pool.checkInterval", 1000);
CustomObjectPool pool = new CustomObjectPool(railsFactory, maxObjects, minIdle, checkInterval);
pool.setMaxWait(getIntegerProperty("jruby.pool.maxWait", 30000));
try {
- pool.addObjects(4);
+ pool.addObjects(1);
} catch (Exception e) {
// ignore
}
Modified: trunk/rails-integration/src/main/java/org/jruby/webapp/RailsTaskServlet.java (626 => 627)
--- trunk/rails-integration/src/main/java/org/jruby/webapp/RailsTaskServlet.java 2007-06-14 12:47:04 UTC (rev 626)
+++ trunk/rails-integration/src/main/java/org/jruby/webapp/RailsTaskServlet.java 2007-06-14 12:48:21 UTC (rev 627)
@@ -15,11 +15,20 @@
new Thread(new Runnable() {
public void run() {
try {
+ // wait until the pool has more than one rails instance available
+ // this allow the app server to start serving requests before initializing all tasks
+ while (getRuntimePool().getNumIdle() <= 2) {
+ try {
+ Thread.sleep(5 * 1000);
+ } catch (InterruptedException ignore) {
+ }
+ }
+
while (true) {
Ruby runtime = (Ruby) getRuntimePool().borrowObject();
servletConfig.getServletContext().log("Starting " + script);
try {
- runtime.evalScript("load(RAILS_ROOT + '/" + script + "')");
+ runtime.evalScript("load(File.join(RAILS_ROOT, '" + script + "'))");
} catch (Exception e) {
getRuntimePool().invalidateObject(runtime);
try {
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel