From: normalperson at yhbt.net (Eric Wong)
Subject: [PATCH (WIP)] limit CPU usage of cgit processes
Date: Wed, 21 Mar 2012 01:52:54 +0000 [thread overview]
Message-ID: <20120321015254.GA23083@dcvr.yhbt.net> (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
next reply other threads:[~2012-03-21 1:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-21 1:52 normalperson [this message]
2012-03-21 7:23 ` mailings
2012-03-21 7:31 ` normalperson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120321015254.GA23083@dcvr.yhbt.net \
--to=cgit@lists.zx2c4.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).