Announcing MediGuest: Free Management software for Social Welfare Hostels

I’ve just released MediGuest. It’s an web-based, open-source application for the management of welfare hostels. Think of drug rehab centers, centers for alcoholics, or anywhere that may admit guests, but also supervise them in some way.

Previously commercial, I’m making this available to all organisations that can benefit from it, entirely free of charge… because, god knows, we need more people doing what you guys do, and we all should support you better in doing it.

MediGuest features include:

An appeal for correct, capable, future-proof math in nascent programming languages

Let me start by saying that, the math in most programming languages is WRONG.  In most cases, there is little to be done about this, except perhaps tack on some new classes which allow new code to be written to fix it.

However, nascent languages, like Rust, which I’ll mainly address here, have an opportunity to do better. I believe they SHOULD do better, and so I’m taking a little time, into the small hours, to attempt to make the case. Let’s get started then, bearing in mind that, in the small hours, this won’t be as well-edited, or even well-reasoned, as one might hope ;)

Disqus considered harmful

I just saw yet another interesting blog post that I wanted to contribute a comment to, but bypassed it, because it uses the horrible Disqus comment system.  So, I want to take a moment to rant helpfully point out that using Disqus or third-party comment systems like it will probably do your site (and the internet as a whole) more harm than good.

C++, it’s time to go

I’ve been studying a lot of languages lately, looking for a modern, parallel language which is a deserving successor to C/C++/Python as my main, go-to language for Getting Things Done.  Someone on Reddit was specifically asking why C++ isn’t ideal any more, and I wrote up this response based on my research.  So, I thought I’d repost it here, too.

Let’s get right into what’s wrong with C++, then, and why I’d sooner replace it.

Projects, old and new

NOTE: See my GitHub page, for a complete list of public projects.

I’ve recently taken a few projects out of storage (literally: the mountpoint is called “storage” :), and posted them on GitHub.  So, I thought I’d take a moment to point out each one.  I’m also going to get into some current projects, which will be appearing on GitHub one of these days.

Game complexity, and the art of programming

Someone asked on reddit:

“How lines of text (coding) can turn into beautiful, complex environments in games?”

I wrote up a quick reply, which I liked enough to post here instead.  I should really take the time to write it more carefully, building the explanations, evidence, etc.  That could be a powerful read, or maybe even a programmer’s manifesto of sorts ;)   But I’m lazy, and I sometimes enjoy the quick flow of prose as much as the precision of slowly, carefully spelling out details.  So, I’m going to leave it like this, for now :)

There are hand-drawn graphics etc., but I don’t think that’s what you’re getting at.

The kind of beautiful complex you’re talking about is exactly what the beauty and joy of programming is about: creating beautiful, complete worlds, using the simplest, most elegant models you can think of. It’s really a lot like how the real world works: animals, plants, etc., all come from very simple DNA codes. Proteins etc. are built from those simple codes, being processed according to simple rules. This happens billions of times. Those created proteins etc. form cells in accordance with other simple rules, and those cells react to light, gravity, water, etc. according to other rules. Organs interact according to their rules, people react according to their rules and their own unique attributes (just like earlier, proteins were built according to the unique attributes of DNA)…So, on and on, we have this ever increasing complexity, built from very simple principles acting on other simple principles and individual variables.

Eventually, you reach a point where complex organisms feel the sun on their skin, smile, grab a girl’s hand, and go running through a field, feeling the wind on their face, turning to see the stars in another’s eyes, etc.

Beautiful complexity, from simple elegance. It’s art. It’s poetry. It’s engineering. It’s a new form of art, and yet it’s the same art humans have made, following the same rules except with different variables, since they first scratched on the wall of a cave.

You might want to read up on complex systems / complexity theory / chaos theory, genetic algorithms, conway’s game of life, and similar topics for more on this.

Or just go look at a bridge ;)

Tuning a webserver to avoid swapping

A lot of people run into a problem when they first setup a webserver — perhaps in a VPS or other small system — using default settings: the system will run fine at first, but when under load, probably when the owner isn’t around, it will grind to a halt. The owner comes back, tries to use the site, and it’s unbearably slow. Even logging into the server to see what’s wrong, can be unbearably slow.  The worst thing, but the common thing, is to log in eventually, reboot the server, and continue as before.

The usual cause of this is not realising that web / database servers need to be configured carefully for the memory use per connection.

For example, if you’re just running apache with mod-php, and PHP is configured for 128MB per connection, apache might default to 32 connections or more (it might even be 128 by default), which is a LOT of memory for a small VPS. Then there is your database on top, and all of its connections, caches, etc.

For a webserver, you should probably:

  • Turn off virtual memory
  • Carefully calculate your memory requirements for PHP, Ruby, python etc.
  • Run a SMALL number of dedicated fastcgi (or similar, see wsgi etc.) servers for the webapp/languages you need.
  • Tune these as far as reasonably possible. For example, you can configure how much memory PHP-FPM will use, and how many threads mongrel will spawn, etc.
  • Run a carefully tuned webserver, with lots of LIGHTWEIGHT connections: apache stripped down (google that) or nginx, or lighttpd. I’d recommend nginx.
  • Run these without in-process languages like mod-php. Instead, make them serve static files quickly (ideally using the linux kernel’s sendfile feature), but pass PHP requests etc. to the back-end handlers, like php-fpm via fastcgi or similar.
  • Run mysqltuner or similar tools to tune your database.

What you need to aim for is for the maximum number of processes, under full load, and full memory usage, plus any extra software like firewalls and cron jobs, to never exceed physical memory. If you do need to run heavy cron jobs etc., then enable virtual memory, but only if you’re sure there are quiet times for your server, like 3am, when it can afford to crawl. Otherwise, you need to take the hit and reduce the number of processes/maximum memory, or increase the server memory, to cope without swapping.

UK Interest Rates: Government figures vs. Government figures

Officially, the UK Inflation rate is 2.4%. Except that inflation is supposed to be “a measure of the rise in cost of goods and services“.

Based on actual figures from the Office of National Statistics, the same organisation that reports the inflation rate, things are very different:

Gas and electricity: +142%
Car tax & insurance +108%
Home insurance: +54%
Council tax and rates +49%
(and so on)

The two are highly out of sync. On the one hand, you have huge actual rises in the cost of living. On the other hand, you have methodologies that make everything look right as rain. In fact, they have the audacity to claim that interest rates are falling, to 2.4%.

When inflation gets really bad (when hyperinflation occurs), the end result is that the economy collapses, or has to take extreme measures known as to prevent collapse. We’re not there yet, but this should be starting to sound familiar.

And yet, they have the audacity to claim that interest rates are falling, to 2.4%.

This is how you know your country is slipping… not into recession, but into global irrelevance.

As Her Majesty might say, one would do well to learn Chinese soon.

PyPy vs. CPython: Speed and memory usage benchmarks

Following on from part 1 of this article, I’d like to take you through some PyPy vs. CPython benchmarks.

Benchmarks: Many Objects

Note: in all benchmarks, I’m measuring total memory use for the entire interpreter run, but only measuring time taken across the code I’m actually interested in testing. There’s a subtle (depending on your experience) difference, because the interpreters may take longer to start up and shut down before actually running. From my perspective, it seems wiser to ignore this startup time, since most applications may run for a long time, and users are interested in performance once running, rather than during startup/shutdown. Either way, the startup/shutdown time is neglible for both interpreters, in this case.

Let’s take a quick benchmark of CPython vs. PyPy. This simple script will take a number on the command line, and generate that number of objects, each containing a dictionary of 30 sub-objects, which in turn contain simple string values as fields.

On the virtues of PyPy as your default interpreter

I get a lot of use out of PyPy. In fact, it’s become my default python interpreter, replacing CPython, at least for Python 2.x code. Python 3.x support in PyPy is coming real soon now; most of the tests are passing, so the next release will probably make it happen.

So, I wanted to write a little about the virtues of PyPy, and its potential to be your default Python interpreter, too. I also want to talk about the main issues that might present roadblocks at the moment, and how you might work around them. Finally, while most benchmarks focus on PyPy’s speed, I’m also going to examine its memory usage.

Welcome to my new blog

It’s been a while.  Finding time to blog is tough these days, and it’s so easy to be swept up in sites like Facebook, where all your friends are, or Google Plus, which offer easy access to lots of other posts and readers.

I’ve seen the light, though. Facebook does so much analysis on users for so little in return, and limits your network size, etc.  When I last had a blog, I had complex, interesting discussions with people from all over the world, regularly.  For all my time on Facebook, I’ve said hi to a few friends, arranged a few outings, checked out a bunch of photos… but the whole experience has been much more shallow.  Granted, Google Plus is better at that sort of open discussion.  But then there are the privacy issues.  It’s so hard to track what google plus is sharing, and what it’s not.  And it’s closed.  There isn’t even an API to post to google plus, that I know of. You’d think they’d welcome the content.

In short, I missed the real world-wide web, where people network, communicate, share ideas, and build things together.  So.  A new beginning.

In this blog, I’ll be discussing software engineering projects, mainly in Python, possibly in Rust and a few other modern, interesting languages.  I might get into other projects, like fixing up the new house, garden, sheds, etc.  I might get into ethics, philosophy, and stuff like that, too.  I’ll keep those all neatly categorised though, so people can subscribe to the coding stuff, without listening to me harp on about ethics.  Or vice versa.