The Holy Grail server framework

… and I think I just wrote it.

For years, I have wanted a Python TCP server framework with the following features.

  • Multi-process: I want the framework to be able to use all available processors and cores with no GIL (global interpreter lock) contention.  This is important for CPU-bound applications.
  • Multi-threaded: Each process should have a fixed number of threads so it can multiplex tasks.  This is important for I/O-bound applications.
  • Graceful shutdown: when I issue the kill signal, I want the server to close its server socket immediately, but I want existing connections to have a chance to finish their work.  This is important if the connections are involved in transactions.
  • Graceful code reloading and reconfiguration: when I issue the HUP (hangup) signal, I want the server reload its configuration, spin up new processes, and tell the old processes to stop accepting new connections and shut down only when finished.  Also, the server should only load application code in child processes, so that loading new code is simply a matter of issuing a HUP signal.
  • Transaction integration, including two-phase commit: If the connection dies, I want to roll back the associated transaction automatically, unless the connection dies after the first phase of two-phase commit, in which case I want to leave the transaction in a partially committed state and sort out the issue at a higher level.
  • No proxying: I don’t want all traffic to flow through the master process, which would be bad for both reliability and performance.  Linux (and maybe any Unix system) allows multiple processes to listen on the same server socket; I want to use that feature.

What I have described is well beyond what the Python standard library provides.  In theory, it will let me have all the joys of transactions and zero-downtime updates in a high performance environment.  I have been searching for an implementation of this design for years.  This week, I have been reworking some WingCash code to make better use of transactions and I realized I really need this design.

So, on Monday, I wrote my dream server framework and tried it out… and to my surprise, it actually worked!  I was surprised because I thought that some Python hacker, somewhere, must have tried this experiment by now, and must have failed; otherwise the experiment results would surely be published or mentioned somewhere.  Perhaps my requirements are not very common, the design is not obvious, or I did not type the right search terms.

I am now writing tests for the new server framework, which I am tentatively calling fdtserver (forking distributed transaction server).  I won’t put it into production until it has 100% statement coverage like the rest of WingCash.  I wonder whether fdtserver should be open source.  Doesn’t the need for all those features, particularly graceful code reloading, exist elsewhere?

Cash and hors d’oeuvres

My friends and I have discovered an interesting way to celebrate events like finishing a milestone or the coming of a new year: we’re giving each other cash.  Specifically, today we’re giving each other $20.11.  I’ve never had so much fun passing cash around before.  Suddenly, cash is as cool as a party favor or hors d’oeuvre.  What is it about WingCash that makes cash fun, and will others have this experience, or is it just me?

Cash has always been serious thing for me.  I count and save it carefully.  I have devoted a lot of thought to deciding how to spend it or give it away.  For most of my life, I operated under the impression that money I give away never comes back to me; I believed every cent I receive comes from personal labor.

I would like to relate a little story.  Around the age of ten, I once noticed the design of the packaging of my family’s Commodore 64.  The entire box was a single sheet of corrugated cardboard with no staples, glue, or tape required to maintain the structure.  It had an origami-like flavor: with nothing but folds and cuts, someone had created a box that was strong, easy to open and close, and stayed closed when you wanted it closed.  (At the time, I attributed the brilliant design to Commodore, but today I suspect it is actually a very old design.)

I made my own cardboard box after the same design by cutting a laundry detergent box.  I was impressed to discover my box was built well even though my measurements were not very precise.  That box became one of my treasures.  I made a second, larger one and painted it silver, but the first one lasted longer.  I still have that box now, and it is still sturdy, though it is worn.

That treasured box is where I kept my pile of coins.  I collected coins there for a long time, saving them for something important, though I did not know what.  Those coins had extra value to me because they were stored in my box.  For years, nothing seemed valuable enough to pay for with my coin collection.

In 1999, I finally found a good way to spend those coins.  I spent them on something useful, fun, and not just for me.  I spent them as part of the down payment on my first new car.  I still thoroughly enjoy that car and it still seems to work as well as the day I bought it.  But why did it take so long for me to find something valuable enough to spend my special coins?

I did not think it was right to spend those coins until I found something useful, fun, and not just for me.  Nothing before my car qualified: everything was either just for me or just for someone else, or it was fun but not very useful, or it was useful but not something to get excited about.  A new car is certainly useful, the car I chose is definitely fun (for the driver at least), and it has 4 seats so it was obviously not just for me.

So now here I am, a penny pincher from birth, passing coins around freely.  What changed?  Well, cash has always been useful, but not really very fun, and too formal to call it “not just for me”.  I feel like WingCash is changing that.  The formality of cash is gone; what replaces it seems to be an emerging culture of passing cash around at will and taking what you need.

What makes it fun?  It’s easy, but ease alone does not make something fun.  There has to be some challenge.  The challenge is to use the cash wisely.  I think the wisest thing to do with cash is to help the people around you, especially your family and friends, but also the good people who run businesses and non-profit organizations.  That is who I want WingCash to be good for, in that order: family, friends, businesses, and non-profits.

So happy new year, everyone!  It looks like 2011 is going to be a great year.

Breaking Down Barriers (so I can send you cash)

So here’s the situation: I have some cash I want to give away to people just for signing up at WingCash, but there are still some issues preventing me from doing that:

  • WingCash currently supports very limited jurisdictions for individuals.  Specifically, South Carolina, New Mexico, and Montana.  The support for only those states is based on advice from our lawyers.  We can’t even offer cash to our own family and neighbors yet!  The process of adding jurisdictions is complicated from a legal standpoint.  We’re working on it, but we have to be patient.
  • The sign-up process is easy, but we were asking for people’s birth dates.  Some people might consider that a privacy issue, yet we have no intention of using people’s birth dates in any way except to ensure they are at least 18 years old.  (We do intend to support minors, but in a different way.)

We worked out a simple solution to the second issue: just use a check box instead of asking for a birth date.  The lawyers agreed that it was a good idea, so we have changed the sign-up page.  No birth date is required anymore.

Owners of a business in the United States can participate in WingCash now by signing up and then adding their business.  There is a link to add your business on the WingCash home page.  So, I extend my temporary offer to any legitimate business that signs up at WingCash: I will give you cash!  Once you have cash, you can tweet that cash to other people, redeem it through your bank account, etc.

Of course, people won’t really have the full experience until they can send and receive cash as individuals.  We’ll get there!

WingCash is Open!

I’ve been working on a cool project for the past year.  I haven’t been able to share much about it, but now that it’s open to the public, I intend to talk about it and explore it in the open.  It’s built on Python, Repoze.BFG (to be replaced with Pyramid soon), PostgreSQL, Buildout, and a big pile of other great software.

WingCash is a system for sending cash on the Internet between people and businesses.  It is Brad Wilkes’s idea and dream.  He had the idea while working at FamilySearch.  FamilySearch is trying to help genealogical archives remain financially solvent so that the records they hold can be accessible to the world.  WingCash is completely independent of FamilySearch, but one of the intents is to solve a major financial issue for genealogical archives.

To that end, a foundational principle of WingCash is to charge no fees for direct exchanges of cash between WingCash users.  On WingCash, sending a penny is sensible and economical.  It is also sensible for millions to send a penny apiece to a single recipient.

WingCash does have to charge fees for other kinds of transfers, such as transfers to a bank, since banks charge WingCash for the service.  WingCash will also offer premium services.  But the core service of holding cash and sending it to anyone for no charge will remain free for good.

WingCash currently has limited resources, so please don’t hammer the newborn server, but WingCash does have a design that should allow it to expand into many servers over time.  Check it out and say what you think.  Please add your ideas to the feedback forum.

Here are some topics I expect to cover in future posts about WingCash:

  • I heart
  • Bank notes are back
  • Integration with web stores and donation pages
  • Plans for the API