Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

do not create threads if RubyTimeout == 0.

do not create threads if RubySafeLevel is less than or equal to the current safe level.
added new directive RubyGcPerRequest.
  • Loading branch information...
commit 49da4ddc7a938653b764693af5513699abb685ea 1 parent 040f421
shugo authored
View
1  Makefile.in
@@ -80,6 +80,7 @@ RUBYLIBS = apache/ruby-run.rb \
apache/rd2html.rb \
apache/ruby-debug.rb \
apache/eruby-debug.rb \
+ apache/ruby-profile.rb \
apache/rails-dispatcher.rb \
apache/query.rb \
auto-reload.rb
View
30 mod_ruby.c
@@ -180,6 +180,8 @@ static const command_rec ruby_cmds[] = {
RSRC_CONF, "whether Ruby* directives are restricted from .htaccess"),
AP_INIT_TAKE2("RubyOption", ruby_cmd_option, NULL, OR_ALL,
"set option for application"),
+ AP_INIT_FLAG("RubyGcPerRequest", ruby_cmd_gc_per_request, NULL,
+ OR_ALL, "whether to call GC for each request"),
AP_INIT_TAKE1("RubyHandler", ruby_cmd_handler, NULL, OR_ALL,
"set ruby handler object"),
AP_INIT_TAKE1("RubyTransHandler", ruby_cmd_trans_handler, NULL, OR_ALL,
@@ -1022,19 +1024,22 @@ typedef struct run_safely_arg {
void *arg;
} run_safely_arg_t;
-static VALUE run_safely_0(void *arg)
+static VALUE run_safely_0(VALUE arg)
{
run_safely_arg_t *rsarg = (run_safely_arg_t *) arg;
struct timeout_arg targ;
- VALUE timeout_thread;
+ VALUE timeout_thread = Qnil;
VALUE result;
rb_set_safe_level(rsarg->safe_level);
- targ.thread = rb_thread_current();
- targ.timeout = rsarg->timeout;
- timeout_thread = rb_thread_create(do_timeout, (void *) &targ);
+ if (rsarg->timeout > 0) {
+ targ.thread = rb_thread_current();
+ targ.timeout = rsarg->timeout;
+ timeout_thread = rb_thread_create(do_timeout, (void *) &targ);
+ }
result = (*rsarg->func)(rsarg->arg);
- rb_protect_funcall(timeout_thread, rb_intern("kill"), NULL, 0);
+ if (!NIL_P(timeout_thread))
+ rb_protect_funcall(timeout_thread, rb_intern("kill"), NULL, 0);
return result;
}
@@ -1052,8 +1057,13 @@ static int run_safely(int safe_level, int timeout,
#if defined(HAVE_SETITIMER)
rb_thread_start_timer();
#endif
- thread = rb_thread_create(run_safely_0, &rsarg);
- ret = rb_protect_funcall(thread, rb_intern("value"), &state, 0);
+ if (safe_level > ruby_safe_level) {
+ thread = rb_thread_create(run_safely_0, &rsarg);
+ ret = rb_protect_funcall(thread, rb_intern("value"), &state, 0);
+ }
+ else {
+ ret = rb_protect(run_safely_0, (VALUE) &rsarg, &state);
+ }
rb_protect(kill_threads, Qnil, NULL);
#if defined(HAVE_SETITIMER)
rb_thread_stop_timer();
@@ -1134,6 +1144,7 @@ static VALUE exec_end_proc(VALUE arg)
static void per_request_cleanup(request_rec *r, int flush)
{
+ ruby_dir_config *dconf = get_dir_config(r);
VALUE reqobj;
while (r->next)
@@ -1165,7 +1176,8 @@ static void per_request_cleanup(request_rec *r, int flush)
restore_env(r->pool, rconf->saved_env);
}
rb_progname = Qnil;
- rb_gc();
+ if (dconf->gc_per_request)
+ rb_gc();
}
typedef struct handler_0_arg {
View
4 mod_ruby.h
@@ -181,6 +181,7 @@ typedef struct {
int output_mode;
array_header *load_path;
table *options;
+ int gc_per_request;
array_header *ruby_handler;
array_header *ruby_trans_handler;
array_header *ruby_authen_handler;
@@ -206,9 +207,10 @@ typedef struct {
VALUE request_object;
} ruby_request_config;
-#define MR_DEFAULT_TIMEOUT 270
+#define MR_DEFAULT_TIMEOUT 0
#define MR_DEFAULT_SAFE_LEVEL 1
#define MR_DEFAULT_RESTRICT_DIRECTIVES 0
+#define MR_DEFAULT_GC_PER_REQUEST 0
#define MR_OUTPUT_DEFAULT 0
#define MR_OUTPUT_NOSYNC 1
View
10 ruby_config.c
@@ -100,6 +100,7 @@ void *ruby_create_dir_config(pool *p, char *dirname)
conf->output_mode = MR_OUTPUT_DEFAULT;
conf->load_path = NULL;
conf->options = apr_table_make(p, 5);
+ conf->gc_per_request = MR_DEFAULT_GC_PER_REQUEST;
conf->ruby_handler = NULL;
conf->ruby_trans_handler = NULL;
conf->ruby_authen_handler = NULL;
@@ -144,6 +145,8 @@ void *ruby_merge_dir_config(pool *p, void *basev, void *addv)
}
new->options = apr_table_overlay(p, add->options, base->options);
+ new->gc_per_request =
+ add->gc_per_request ? add->gc_per_request : base->gc_per_request;
new->ruby_handler =
merge_handlers(p, base->ruby_handler, add->ruby_handler);
@@ -406,6 +409,13 @@ const char *ruby_cmd_option(cmd_parms *cmd, void *conf,
return NULL;
}
+const char *ruby_cmd_gc_per_request(cmd_parms *cmd, void *conf, int flag)
+{
+ check_restrict_directives(cmd, conf)
+ ((ruby_dir_config *) conf)->gc_per_request = flag;
+ return NULL;
+}
+
const char *ruby_cmd_handler(cmd_parms *cmd, void *conf, const char *arg)
{
check_restrict_directives(cmd, conf)
View
1  ruby_config.h
@@ -44,6 +44,7 @@ const char *ruby_cmd_safe_level(cmd_parms*, void*, const char*);
const char *ruby_cmd_output_mode(cmd_parms*, void*, const char*);
const char *ruby_cmd_restrict_directives(cmd_parms*, void*, int);
const char *ruby_cmd_option(cmd_parms*, void*, const char*, const char*);
+const char *ruby_cmd_gc_per_request(cmd_parms*, void*, int);
const char *ruby_cmd_handler(cmd_parms*, void*, const char*);
const char *ruby_cmd_trans_handler(cmd_parms*, void*, const char*);
const char *ruby_cmd_authen_handler(cmd_parms*, void*, const char*);
Please sign in to comment.
Something went wrong with that request. Please try again.