27th March 2008, 01:37 pm
For some reason Apache has started to choak and die. I can watch the memory usage go up and never down. Looking around the web I’m seeing that PHP has memory leak issues and so does Apache 2.0.x on Windows. Apparently it’s difficult to free up any memory you allocate. Sure tools exist that will tell you if your program is freeing up all your memory but why expect people to actually use them?
For Win32 there’s some voodoo to be done to “fix” the problem.
Win32DisableAcceptEx
…
ThreadsPerChild 250
MaxRequestsPerChild 100
For whatever reason Apache 2 will start throwing out errors about AcceptEx on Windows. So you have to disable it to keep Apache happy.
The second issue is the requests per child. By default it’s zero. That means accept as many as you want. That would be fine if each of those requests ended with a zero change in memory usage. But somewhere along the line memory doesn’t get freed up. So you have to tell Apache to restart the child after X amount of requests.
It appears to be working.
I’m debating whether or not to upgrade to the 2.2 line of Apache but apparently the issue shows up with that version of Apache as well. My guess is that it is a problem with PHP. But I havn’t mucked around enough to figure out if there’s something I can do in PHP to manually get the memory cleared up.
25th March 2008, 03:22 pm
I may at some point repost some of the old blog posts on Dawn of the Geeks but I highly doubt it. FreeRingtoneHeaven.com has been updated to use the new javascript generated links. The main Dawn of the Geeks page redirects to here. I also installed a new wiki to replace the ancient one currently running on Dawn of the Geeks. All the pages were copied over and the old wiki will just be deleted. Last year the wiki got virtually no hits so redirecting isn’t even necessary.
I’m still trying to figure out what to do with all the programming related material.
25th March 2008, 10:25 am
Reverse DNS is a great thing when it works. It allows the web-server to figure out more meaningful information from an IP address. The problem is that DNS servers can be unreliable in terms of performance.
Yesterday I was noticing that my sites were taking a long time to load. I traced the problem back to establishing a connection to the database server. So I changed the DNS server so it wouldn’t do a reverse DNS lookup. That didn’t fix it. I then turned off HostLookup on Apache and now my sites load just fine.
Reverse lookup is not really needed anymore since Google Analytics takes care of that end. It’s also possible to do reverse lookup later. Apache doesn’t need it for anything. It’s just informational. And I care more about performance than optional information about visitors.
Eventually I may even turn of logging except for the error logs. But, I need to get things organized better still.
25th March 2008, 10:19 am
Javascript used to be the last thing you wanted on your web-site. It would inevitably be disabled because of all the supposed security issues. These days javascript is everywhere. Web site owners have figured out that it is incredibly useful.
In order to keep my web-sites linked together without having to maintain a dozen different sets of links I’ve devised a PHP script that generates the javascript necessary to render the links from a central database. So now if I want to add links to a web-site I just paste in some javascript code and set the font to match the site. In fact, the links off to the side are generated from the javascript.
In the future I may create some advanced functionality and offer some sort of co-op program. But for now it’s just to keep all my own sites in sync.
23rd March 2008, 08:44 pm
One of the constant issues with a large web-site is maintaining it. Many of my web-sites have a blog running in the background somewhere and a custom front end. For Dawn of the Geeks I’ve decided to switch gears and run a full fledged blog. There will be zero custom code for the front-end of Dawn of the Geeks.
Last year I picked up a few new domains and this year I will pick up one or two more and get rid of several. I like to constantly try new things and sometimes they work and sometimes they don’t. If a domain cannot earn the cost of the domain in one year (about $9) I get rid of it.
The other issue is maintaining links. Since sites are coming and going and moving around it’s difficult to maintain a static page. Now, all my sites will be listed off to the side and that list of sites will be available to any other web-site through a dynamically generated JS file. This will keep my network of sites interlinked through a central blogroll without requiring that all my sites reside on the same server.
Hopefully the coming changes will result in a better Dawn of the Geeks.
15th March 2008, 03:43 am
//test a
double functional(double a, double b)
{
return a + b;
}
//test b
double nonfunctional()
{
return a + b;
}
//test c
double functional_no_param()
{
double a = rand.NextDouble();
double b = rand.NextDouble();
return a + b;
}

For Test B the variables a and b are class variables of type double and are set to rand.NextDouble() prior to the function call.
I was getting odd results before because I was simply declaring a variable, setting it to rand.NextDouble() and returning it. In that case the compiler was optimizing the code to essentially be “return rand.NextDouble()” That’s why it appeared that the functional way was faster.
However, once you start passing parameters you start to see a lot of overhead. You can see that it’s actually faster to declare a local variable (Test C) than to pass the values in (Test A). But, optimally the variables are predefined and you simply set the values.
So while functional programming may be easier to test and reuse, it suffers significant slow downs.
Safe mode is probably faster because C# may be switching modes. The “unsafe” code is the loop that calls the function a bunch of times. So you don’t want safe code to call unsafe code. You lose performance that way instead of gain it.
Test B benefits from unsafe because most of the work is done in the unsafe portion of code.
15th March 2008, 12:16 am
Functional programming is simply writing functions that only operate on the given parameters and local variables and then return a value.
//functional programming
int add(int a, int b) { return a+b; }
//not functional programming
int a,b;
a=2;
b=3;
int add() { return a+b; }
Functional Programming is great in theory because you can test functions easily. You just call the function with values and check to see if the returned value matches the expected value.
In non-Functional Programming you may have to create some global values before you can test the function.
I’ve been running some tests in C# and am finding that it is actually faster to declare a variable locally and act on it than to use a variable defined at the class level. I’m going to keep running tests to verify these results.
14th March 2008, 04:04 am
Getting data out of an array is a pretty common occurance in programming. So I decided to find out what the fastest method was for getting data out of a two dimensional array. There are two basic methods, you can use a real two dimensional array or you can use a single dimension array and treat it like a two dimensional array with some simple math. I ran the test in release and debug mode and found that either DevPartner profiler doesn’t do release mode well or I didn’t know how to configure it properly because debug mode came back with faster results. So these two sets of results are broken apart and the idea is to show the difference, not hard numbers.
The left side numbers are the number of milliseconds it took to get the values of an array at 1 million random points.

Debug Mode
I did two runs for each of the six tests. There are three methods used to get the array value and they are done in safe and unsafe mode. The middle marker is the average of the two tests.
You can see in this test that [x+y*n] where n is the width of the array is the fastest method. One of the oddities is that [x,y] (C#’s 2 dimensional array) is faster when it’s done in safe mode.
Using a shift can be faster instead of a multiply can be faster and probably is with enough tests.

Release Mode
Release Mode came back with more consistant results. Here we can see that shifting is faster than multiplying. Which is to be expected.
In both debug and release mode you can see that when dealing with arrays you don’t want to use C#’s method and instead use simple math in unsafe mode. Based on the numbers collected the shift vs multiply gets you about a 1% speed boost. That doesn’t seem like a whole lot but when you’re accessing arrays millions of times per second it adds up.
Also, for these tests in all cases the array was 2048×2048. In a second set of tests the 2d array and the multiply had an array size of 127×127 while the shift test had an array size of 128. In that case there is about a 7-8% speed increase by using shifts. The multiply is probably being treated virtually like a shift by the CPU when it’s a power of 2.
The drawback to shifting is that you must use powers of two for the array width which could lead to wasting memory or imposing restrictions on various things such as texture or map size.
This is why graphics cards restrict everything to powers of two. It’s more efficient to shift than to multiply.
14th March 2008, 01:44 am
One of the things I noticed in my performance logs was that returning values from an array was a little slow.
http://msdn2.microsoft.com/en-us/magazine/cc301755.aspx talks about C# and arrays and mentions that by default C# does bounds checking on arrays. Well, my functions are already doing bounds checking. So to turn off C#’s bounds checking you simply put the code in an “unsafe” block.
The result is a couple more FPS.
My next test is to see which is faster: a single dimension array using a multiply or a two dimensional array.
11th March 2008, 10:14 pm
One of my Seagate drives finally failed completely. So bunnies.dawnofthegeeks.com and other sites are temporarily down. I just ordered a new Western Digital SATA drive from NewEgg and it should be here later this week. It’s nothing I wasn’t expecting. I’ll be replacing the old IDE drives as they fail with new SATA drives.
There are two IDE drives left in the server. One has the server logs and the other has the database information. I’m going to limit the number of sites that have access logs to cut down on drive usage as well as speed up the load time for web-sites. Google Analytics works great so I don’t need to waste time dealing with logs.
As for the database I’m going to have to work out a backup plan because I’m sure that drive will be failing next.