It’s been a long time coming, but we’ve just published our Twitter-internal MySQL development branch onto GitHub. The initial publication and announcement isn’t meant to be groundbreaking—we’re setting up some groundwork to be able to collaborate publicly. It comes with an initial set of changes we’ve made to support our production workloads and make DBAs lives easier, which you can read about in the README.
Author Archives: Jeremy Cole
Kiva: How to make a difference for 1,000 people with only $100 per month
Kiva (also see my lender page) is an amazing and deceptively simple idea: People, mostly in third world countries, need loans to buy food, crops, cows, equipment, education, etc. so they get a loan from a local Kiva partner, and those loans are backed by Kiva users in $25 increments. There is no interest paid to Kiva users, (although the local partners do charge some interest), so it’s not really an investment per se.
I’ve been a user of Kiva for a more than five years now, and have made 350 loans so far for a total of $9,400 loaned. In the first few years I only sporadically made some loans and let repaid money sit around for a long time. In the past couple of years I’ve been using Kiva more consistently, every month re-investing the full repayment amounts as soon as they come in, and usually adding 4-6 loans ($100-$150) of new money.
As I’ve been doing this I noticed an effect that makes perfect sense but I hadn’t considered before: Since the loans are anywhere from 9-24 months, but the repaid amounts are repaid typically monthly, if the repaid amounts are re-invested immediately, the original loan amounts stack on top of each other, allowing the same money to be invested several times over simultaneously.
Recently I’ve been thinking about actually quantifying that effect and figuring out what impact it could have. Since it’s not a very simple calculation, I put together a spreadsheet to calculate the full picture for me.
Assumptions
The following assumptions are made:
- Amount per loan: $25.00 — This is the standard loan amount on Kiva, so this just assumes you never double up on a single loan (which is not a good idea as it spreads the loss risk poorly).
- Investment per month: 4 loans, or $100 (and reinvest all repayments) — This is approximately what I’ve been doing, although frequently it’s a bit more than 4.
- Average loan duration: 15 months — This is the average loan duration for my loan portfolio, and seems about average for Kiva.
- Loss rate: 2.07% — This is the actual loss rate of my portfolio, which is a bit higher than the average Kiva user at 1.09% because I tend to loan to war-torn and riskier areas.
Results
After 5 years (60 months) of consistent and prompt investment, the results could be:
- Total investment: $6,000 — This is the actual amount you’ve paid out of pocket.
- Total loans made: 1,004 — The number of individuals or groups helped. This is the most amazing thing, watching all of these individuals succeed due to your help.
- Total amount loaned: $25,100 — The amount your $6,000 turns into after re-investment through immediate re-loaning.
- Total amount lost: $519.57 — Due to a combination of loan defaults and currency exchange loss, not all of your money will be returned.
- Total amount returned: $5480.43 — If you stopped making loans after the 60 months and started to withdraw your money from Kiva, at the end of it you’d get this much back (investment minus loss).
Check out the full calculator on Google Docs for all the details and per-month amounts.
Conclusion
The really amazing thing with following this plan is that the Kiva borrowers themselves end up—through prompt repayment of their loans—funding each other. For me, the amount being invested each month is quite modest, and through reinvestment of the repayments, the monthly impact is huge. This month, I received almost $400 in repayments, added an additional $100, and made $500 in new loans.
Vector: A new way to think about replication performance and replica lag
Background
I have been considering a new way to think about, measure, graph, and monitor replication lag for a while. Previously I’ve always been primarily been using replication delay (lag), in seconds. Initially this came from SHOW SLAVE STATUS‘s Seconds_Behind_Master field, later replaced by mk-heartbeat‘s delay information. (These are equivalent, but mk-heartbeat is less buggy and works to represent true lag with relay replicas in the replication topology.) Using delay in seconds to monitor replication has a few problems though:
- The current number of seconds delayed provides no information about how long it might take to catch up.
- It’s very difficult to determine whether a replica is catching up at all, due to the scale. If a replica is a few thousand seconds behind it’s hard to tell whether it’s catching up, falling behind, or neither, at any particular moment.
- If multiple replicas are graphed together, they may have widely different absolute delay values, and thus scales, and it can be very difficult to compare them, or to see that a replica is having problems, until it’s too late. Two replicas may be falling behind at the same rate, but if one is 300 seconds behind, and one is 20,000 seconds behind, the graphs are difficult to interpret.
Given these problems, I determined that while we need the absolute delay information available, it’s not good enough by itself. I started to think about what it is that I’m really trying to determine when looking at the delay graphs.
Vector: Velocity and direction
The key bits of information missing from the delay information seem to be:
- Is the replica falling behind, catching up, or neither? We need a measure of the direction of replication’s delay.
- How fast is the replica falling behind or catching up? We need a measure of velocity of replication’s performance
Fortunately these two things can be combined together into a single number representing the vector of replication. This can then be presented to the user (likely a DBA) in an easy to consume format. The graphs can be read as follows:
- Y = 0 means the replica is neither catching up nor falling behind. It is replicating in real time. I chose zero for this state in order to make the other two states a bit more meaningful and to make the graph symmetric by default.
- Y > 0 means the replica is catching up at Y seconds per second. There is no maximum rate a replica can catch up, but in practice seeing velocities >1 for extended periods is relatively uncommon in already busy systems.
- Y < 0 means the replica is falling behind at Y seconds per second. As a special case, Y = -1 means that the replica is completely stopped and playing no events. Lagging is a function of the passage of time, so it is not possible to lag faster than one second per second.
I like the symmetry of having the zero line be the center point, and having healthy hosts idle with a flat line at zero. Lag appears in the form of a meander away from zero into the negative, matched by an always equal-area1 (but not necessarily similarly shaped) correction into the positive. In practice the Y-scale of graphs is fixed at [-1, +1] and the graphs are very easy and quick to interpret.
Example 1
Most replicas are replicating real time; one replica fell behind for some time before catching up again.

Vector – A few small perturbations can be seen, and one replica replicated at less than real time time for many hours, before finally crossing over zero and catching up at an increasing rate until current time was reached.

Delay – The small perturbations are difficult to see due to the scale imposed by the one very delayed replica. Although it’s easy to see on a day view that the replica did catch up quickly, that is less obvious when monitoring in real time.
Example 2
Many replicas with different replication rates, and a lot of trouble.

Vector – Overall replication performance is quite poor, and shows evidence of being unlikely to catch up to current time or maintain real time replication in the future.

Delay – It’s difficult to know if things are getting better or worse. The replication performance of each host is almost impossible to compare.
Implementation
In basic terms, the number of seconds of replication stream applied per second of real time, should be measured frequently, and with reasonably good precision. I have mk-heartbeat writing heartbeat events into a heartbeat table once a second on the master (which has an NTP-synchronized clock), providing a ready source of the progression of “replicated heartbeat time”2 (htime) to the replicas. The replicas of course have their own NTP-synchronized clocks providing a source of local “clock time” (ctime). Both of these are collected on each replica once a minute, as integers (Unix epoch timestamps). Both the current sample (subscript c) and the previous successful sample (subscript p) are available to the processing program. The vector is calculated, stored, and sent off to be graphed once per minute.

The implementation is actually quite simple, and tolerant of almost any sampling interval. In the future it could be extended to use millisecond resolution (although it can never be any higher resolution than the frequency the heartbeat is updated).
1 This is kind of an interesting point. Since the graph is nicely centered on zero, negative numbers represent the exact same scale as positive numbers, on the same dimensions.
2 SELECT UNIX_TIMESTAMP(ts) AS ts FROM heartbeat WHERE id = 1
Migrating to WordPress.com hosting
As I get older I realize how much I don’t want my personal life to feel like my work life. I’ve been running my own WordPress.org installation for years, and it’s been easy and not really a problem. However it does also mean maintaining Linux, Apache, PHP, and other supporting infrastructure, and keeping things updated and upgraded all the time. My usage of WordPress is remarkably simplistic, so I really don’t need to do all of that. I decided to migrate to a paid WordPress.com hosted account instead.
As part of this migration I also changed the URL structure a bit, to match WordPress.com’s directory structure and make things simpler (and easier to move in the future if I want to). There is a mod_rewrite redirector in place to keep the old URLs working forever. (I hope.) The changes are:
- Moving from jcole.us/blog to blog.jcole.us.
- Removing archives/ from the permalink path structure.
- Simplifying the theme a bit. It’s pretty generic right now, but I’ll fix it up some more in the future.
January 2011 MySQL Meetup: Clustrix
Clustrix will be presenting at this month’s Silicon Valley MySQL Meetup in Sunnyvale, CA. Stop by if you can!
Paul Mikesell (CEO and VP Engineering) and Aaron Passey (CTO) will be discussing the unique architecture behind Clustrix’s massively scalable, distributed, MySQL-compatible database solution. They will talk about how the company has addressed the common challenges associated with achieving massive scale for transactional (OLTP) relational workloads.
Prior to developing the Clustrix solution over the past four years, Paul was co-founder of Isilon Systems, just acquired by EMC in December 2010 for $2.25B and still has the largest clustering capability (>120 nodes) of any NAS solution.
