r11908 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r11907‎ | r11908 | r11909 >
Date:10:28, 2 December 2005
Author:vibber
Status:old
Tags:
Comment:
hacked in a hard connection limit
Modified paths:
  • /trunk/mwsearch/Daemon/Daemon.cs (modified) (history)
  • /trunk/mwsearch/Daemon/HttpHandler.cs (modified) (history)
  • /trunk/mwsearch/Daemon/Worker.cs (modified) (history)

Diff [purge]

Index: trunk/mwsearch/Daemon/HttpHandler.cs
@@ -45,6 +45,30 @@
4646 ostrm = new StreamWriter(stream);
4747 }
4848
 49+ private static int _openCount = 0;
 50+ private static object _countLock = new object();
 51+
 52+ public static int OpenCount {
 53+ get {
 54+ lock (_countLock) {
 55+ return _openCount;
 56+ }
 57+ }
 58+ }
 59+
 60+ private static void _Enter() {
 61+ lock (_countLock) {
 62+ _openCount++;
 63+ }
 64+ }
 65+
 66+ private static void _Leave() {
 67+ lock (_countLock) {
 68+ _openCount--;
 69+ }
 70+ }
 71+
 72+
4973 public void Run(object par) {
5074 Run();
5175 }
@@ -53,6 +77,7 @@
5478 //using (log4net.NDC.Push(client.Client.RemoteEndPoint)) {
5579 headersSent = false;
5680 try {
 81+ _Enter();
5782 Handle();
5883 log.Debug("request handled.");
5984 } catch (IOException e) {
@@ -68,6 +93,7 @@
6994 // Make sure the client is closed out.
7095 try { ostrm.Close(); } catch { }
7196 try { istrm.Close(); } catch { }
 97+ _Leave();
7298 }
7399 }
74100
Index: trunk/mwsearch/Daemon/Daemon.cs
@@ -44,6 +44,7 @@
4545 private static Configuration config;
4646
4747 private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
 48+
4849
4950 public static void Main(string[] args) {
5051 Console.WriteLine(
@@ -76,6 +77,11 @@
7778 }
7879 sock.Start();
7980
 81+ int maxWorkers = 10;
 82+ string max = config.GetString("Daemon", "maxworkers");
 83+ if (max != null)
 84+ maxWorkers = int.Parse(max);
 85+
8086 /*
8187 log.Debug("Blah blah debug");
8288 log.Info("Blah blah info");
@@ -93,8 +99,13 @@
94100 log.Error("accept() error: " + e.Message);
95101 continue;
96102 }
97 - Worker worker = new Worker(client.GetStream(), config);
98 - ThreadPool.QueueUserWorkItem(worker.Run);
 103+
 104+ if (Worker.OpenCount > maxWorkers) {
 105+ log.Error("too many connections, skipping a request");
 106+ } else {
 107+ Worker worker = new Worker(client.GetStream(), config);
 108+ ThreadPool.QueueUserWorkItem(worker.Run);
 109+ }
99110 }
100111
101112 }
Index: trunk/mwsearch/Daemon/Worker.cs
@@ -75,6 +75,7 @@
7676 this.config = config;
7777 }
7878
 79+
7980 protected override void DoStuff() {
8081 if (uri.AbsolutePath == "/robots.txt") {
8182 RobotsTxt();

Status & tagging log