List for cgit developers and users
 help / color / mirror / Atom feed
* [PATCH (WIP)] limit CPU usage of cgit processes
@ 2012-03-21  1:52 normalperson
  2012-03-21  7:23 ` mailings
  0 siblings, 1 reply; 3+ messages in thread
From: normalperson @ 2012-03-21  1:52 UTC (permalink / raw)


Here's a work-in-progress patch which I've been running to
prevent crawlers/bots from using up all the CPU on my system
when doing expensive queries.

If it's interesting, it should be wired up to appropriate
config option...

Signed-off-by: Eric Wong <normalperson at yhbt.net>
---
 cgit.c |   13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/cgit.c b/cgit.c
index 1d50129..285467c 100644
--- a/cgit.c
+++ b/cgit.c
@@ -768,12 +768,25 @@ static int calc_ttl()
 	return ctx.cfg.cache_repo_ttl;
 }
 
+#include <sys/time.h>
+#include <sys/resource.h>
+static void init_rlimit(void)
+{
+	struct rlimit rlim = { .rlim_cur = 10, .rlim_max = 10 };
+	if (setrlimit(RLIMIT_CPU, &rlim) != 0) {
+		perror("setrlimit");
+		exit(EXIT_FAILURE);
+	}
+}
+
 int main(int argc, const char **argv)
 {
 	const char *path;
 	char *qry;
 	int err, ttl;
 
+	init_rlimit();
+
 	prepare_context(&ctx);
 	cgit_repolist.length = 0;
 	cgit_repolist.count = 0;
-- 
Eric Wong




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH (WIP)] limit CPU usage of cgit processes
  2012-03-21  1:52 [PATCH (WIP)] limit CPU usage of cgit processes normalperson
@ 2012-03-21  7:23 ` mailings
  2012-03-21  7:31   ` normalperson
  0 siblings, 1 reply; 3+ messages in thread
From: mailings @ 2012-03-21  7:23 UTC (permalink / raw)


how about using a robots.txt on your site?

On 21-03-12 02:52, Eric Wong wrote:
> Here's a work-in-progress patch which I've been running to
> prevent crawlers/bots from using up all the CPU on my system
> when doing expensive queries.
>
> If it's interesting, it should be wired up to appropriate
> config option...
>
> Signed-off-by: Eric Wong<normalperson at yhbt.net>
> ---
>   cgit.c |   13 +++++++++++++
>   1 file changed, 13 insertions(+)
>
> diff --git a/cgit.c b/cgit.c
> index 1d50129..285467c 100644
> --- a/cgit.c
> +++ b/cgit.c
> @@ -768,12 +768,25 @@ static int calc_ttl()
>   	return ctx.cfg.cache_repo_ttl;
>   }
>
> +#include<sys/time.h>
> +#include<sys/resource.h>
> +static void init_rlimit(void)
> +{
> +	struct rlimit rlim = { .rlim_cur = 10, .rlim_max = 10 };
> +	if (setrlimit(RLIMIT_CPU,&rlim) != 0) {
> +		perror("setrlimit");
> +		exit(EXIT_FAILURE);
> +	}
> +}
> +
>   int main(int argc, const char **argv)
>   {
>   	const char *path;
>   	char *qry;
>   	int err, ttl;
>
> +	init_rlimit();
> +
>   	prepare_context(&ctx);
>   	cgit_repolist.length = 0;
>   	cgit_repolist.count = 0;

-- 
Ferry Huberts





^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH (WIP)] limit CPU usage of cgit processes
  2012-03-21  7:23 ` mailings
@ 2012-03-21  7:31   ` normalperson
  0 siblings, 0 replies; 3+ messages in thread
From: normalperson @ 2012-03-21  7:31 UTC (permalink / raw)


Ferry Huberts <mailings at hupie.com> wrote:
> how about using a robots.txt on your site?

I actually do want most cgit content to be searchable.
It's just that generating some pages is expensive and burns CPU.

I haven't had time to investigate which/why some pages are expensive,
but the SIGXCPU route will still save servers if there are unexpected
surprises.




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-03-21  7:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-21  1:52 [PATCH (WIP)] limit CPU usage of cgit processes normalperson
2012-03-21  7:23 ` mailings
2012-03-21  7:31   ` normalperson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).