Like I wrote last time, my PHP-program ran like a charm and was great. Until marketing decided they wanted to change the prize plans on the product. This change required the billing of the product to be done on another billing system and because that billing system was so tightly integrated into everything, it would also require the LDAP to change and we’d need a lot of additional information we didn’t need previously stored in a new database. But, on the bright side, the processing should be simpeler, because now most of the business rules would be implemented in that billing engine and not in my PHP-program anymore and the source database could now (after an update) send changes to existing customers (or new customers) instead of giving us a complete database dump like they did previously.
It looked like life had become simpeler.
Then it was decided that to make the migration easier, we would create a version of my PHP-program that would be somewhere between the old version on the new version. It would accept a complete database dump like it always did, but that dump would be augmented with the additional information we’d need. And that version would already talk to the new billing engine like the new version should (using SOAP). So basically we’d have a version with all the ‘difficult’ old stuff and all the volumious and ‘difficult’ new stuff. The reasoning was good. It should, in theory, make the transition easier, but then again, theory and practice are two different things altogether.
What happened was that with the extra information and the increased userbase (now more then 50,000 users) the memory usage of the program started to exceed the ammount of RAM installed in the machine. Not a problem per se, but the program wasn’t the only program running, so near the end the OS would kill the process because of memory problems. And also, due to hard disk swapping and 1 or more SOAP calls per records (in addition to an LDAP query per record) to program ran slower. A lot slower. It went from 45 minutes to over 14 hours at it’s slowest!
This was a problem.
Fortunatly these problems only got realy bad when I had almost finished the final version of the program. That version would only use changes so the memory usage would be very small and because the amount of changes is relatively small the slow-down because of the SOAP calls is less severe. It now typically runs somewhere between 30 minutes to an hour on an average of 1,000 to 1,500 records. And that’s when it runs once a day, if we double this, the amount of records to process per run are halved with the speed of the run increasing a little more then 100%, so we have some breathing space.
Ofcourse the final version wasn’t perfect. In fact, it was a nightmare. Part of it was due to incorrect specs, part due to missing knowledge on my side (some ’special things’ about PHP I didn’t know) and part was due to the test-process being inadequate.
So what did I learn from this? Well, if I’d had a better development enviroment to program in, lot’s of bugs could’ve been avoided. It can’t debug PHP like I can debug C++ code on Windows. I know there are PHP-debuggers, but I couldn’t get them to work and besides, even if I could, they would be no good, as my desktop wouldn’t be able to reach the test-platform. I could have worked around that though.
No, the biggest problem was that I should’ve figured that the complexity of the program had increased and PHP wasn’t the best solution anymore. I think that in the future I should not be affraid to rewrite part of a program in another programming language, because the added complexity of the new features will make the program harder to make and maintain in the current used language.
If they ever need more complex features, I’ll rewrite the program in C# for sure. That way I can program and test in on my desktop and run it on our application servers thanks to Mono.