Re: Beagle CPU usage (was Proposed module: tracker)
- From: Federico Mena Quintero <federico ximian com>
- To: Bastien Nocera <hadess hadess net>
- Cc: Desktop Devel <desktop-devel-list gnome org>
- Subject: Re: Beagle CPU usage (was Proposed module: tracker)
- Date: Mon, 15 Jan 2007 19:02:11 -0600
El lun, 15-01-2007 a las 16:31 +0000, Bastien Nocera escribi� On Mon, 2007-01-15 at 10:15 -0600, Federico Mena Quintero wrote:
> <snip>
> > We put a call to setrlimit() in gst-office-thumbnailer, so that the
> > helper convert(1) process is limited to 256 MB of memory and 5 seconds
> > of CPU time. Some files do *not* get thumbnailed, of course, but this
> > is better than making the machine unusable.
>
> Neat. I'll try and do something similar for Totem's thumbnailer (it
> currently uses a 30 sec time-limit, so it would be nice to also set a
> certain amount of CPU).
The right fix is to put this in libgnomeui/gnome-thumbnail.c, so that
all thumbnailers get the same treatment. We just did this for
gsf-office-thumbnailer because it was super-urgent (patch attached). I
guess you could use a child_setup_func for g_spawn*() in gnome-thumbnail
to set up the resource limits :)
Federico
2006-12-21 Federico Mena Quintero <federico novell com>
https://bugzilla.novell.com/show_bug.cgi?id=229609 - Limit the
resource consumption of the helper process in gsf-office-thumbnailer.
* thumbnailer/main.c (set_resource_limits): New function. We use
setrlimit() to put a cap on how much resources the helper process
can use, as convert(1) is known to leak tons of memory and CPU on
certain WMF files.
(main): Call set_resource_limits().
--- libgsf/thumbnailer/main.c 2006-12-21 13:37:25.000000000 -0600
+++ libgsf/thumbnailer/main.c 2006-12-21 13:46:12.000000000 -0600
@@ -22,6 +22,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <sys/resource.h>
#include <glib.h>
#include <gsf/gsf-input-memory.h>
#include <gsf/gsf-input-stdio.h>
@@ -212,6 +213,28 @@ read_thumbnail_and_write (const char *in
g_object_unref (input);
}
+#define MAX_HELPER_MEMORY (256 * 1024 * 1024) /* 256 MB */
+#define MAX_HELPER_SECONDS (5) /* 5 seconds */
+
+static void
+set_resource_limits (void)
+{
+ struct rlimit limit;
+
+ /* We call convert(1) from ImageMagick, which is especially scary when converting
+ * WMF thumbnails into PNGs. Convert(1) is known to leak tons of memory and CPU
+ * time on certain WMFs. So, we'll put a cap on how much resources it can use.
+ */
+
+ limit.rlim_cur = MAX_HELPER_MEMORY;
+ limit.rlim_max = MAX_HELPER_MEMORY;
+ setrlimit (RLIMIT_AS, &limit);
+
+ limit.rlim_cur = MAX_HELPER_SECONDS;
+ limit.rlim_max = MAX_HELPER_SECONDS;
+ setrlimit (RLIMIT_CPU, &limit);
+}
+
/* Command-line options */
static int option_size = -1;
static char *option_input_filename = NULL;
@@ -235,6 +258,8 @@ main (int argc, char **argv)
{
GOptionContext *option_ctx;
+ set_resource_limits ();
+
option_ctx = g_option_context_new ("Options");
g_option_context_add_main_entries (option_ctx, option_entries, NULL); /* FIXME: no translation domain */
if (!g_option_context_parse (option_ctx, &argc, &argv, NULL)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]