Archive for the ‘Coding’ Category

Google Chrome beta 6.0.472.33 is Out

Friday, August 13th, 2010

GoogleChrome.jpg

Well... I'm a little surprised (again) at the Google Chrome guys... this time, the update to 6.0.472.33 didn't work from the application, and I had to get the update directly from the web site. In addition, the permissions on the existing app package made it impossible for a new user to replace the old with the new. Very odd. But in the end, I got what I needed, and I hope they have these updating issues fixed. It's amazing that they don't just use Sparkle, it's almost a defacto standard for the Mac.

UPDATE: I see the point... they promoted this to beta from dev, and that's the reason it wasn't updating. I'm going to have to go back to the dev channel when it's on the next major release. Makes sense now.

The Amazing Power of Really Good Design – And Hard Work

Thursday, August 12th, 2010

Today I was very pleased to see that I could add a second exchange feed to the codebase. Yeah... just one day. Pretty amazing. I know it's primarily due to a good design because the number of lines of code I had to write was very few - on the order of 600 lines, but there's still a little bit of good old hard work to attribute to it as well.

But really, it was the design. What a great design. This is something I'm going to enjoy over and over again as I keep working with this codebase. I need to add in at least six more feeds, but if they are only a day or two per feed, I'm still done long before I had expected to be. Amazing.

So after I had it all done, I looked at the code and realized that when I was "unpacking" the time data from the exchange into milliseconds since epoch, I was making a few system calls, and that was going to come back to bite me later as the loads got higher and higher. The original code looked like:

  /*
   * This method takes the exchange-specific time format and converts it
   * into a timestamp - msec since epoch. This is necessary to parse the
   * timestamp out of the exchange messages as the formats are different.
   */
  uint64_t unpackTime( const char *aCode, uint32_t aSize )
  {
    /*
     * The GIDS format of time is w.r.t. midnight, and a simple, 9-byte
     * field: HHMMSSCCC - so we can parse out this time, but need to add
     * in the offset of the date if we want it w.r.t. epoch.
     */
    uint64_t      timestamp = 0;
 
    // check that we have everything we need
    if ((aCode == NULL) || (aSize < 9)) {
      cLog.warn("[unpackTime] the passed in data was NULL or insufficient "
                "length to do the job. Check on it.");
    } else {
      // first, get the current date/time...
      time_t    when_t = time(NULL);
      struct tm when;
      localtime_r(&when_t, &when);
      // now let's overwrite the hour, min, and sec from the data
      when.tm_hour = (aCode[0] - '0')*10 + (aCode[1] - '0');
      when.tm_min = (aCode[2] - '0')*10 + (aCode[3] - '0');
      when.tm_sec = (aCode[4] - '0')*10 + (aCode[5] - '0');
      // ...and yank the msec while we're at it...
      time_t  msec = ((aCode[6] - '0')*10 + (aCode[7] - '0'))*10 + (aCode[8] - '0');
 
      // now make the msec since epoch from the broken out time
      timestamp = mktime(&when) + msec;
      if (timestamp < 0) {
        // keep it to epoch - that's bad enough
        timestamp = 0;
        // ...and the log the error
        cLog.warn("[unpackTime] unable to create the time based on the "
                  "provided data");
      }
    }
 
    return timestamp;
  }

The problem is that there are two rather costly calls - localtime_r and mktime. They are very necessary, as the ability to calculate milliseconds since epoch is a non-trivial problem, but still... it'd be nice to not have to do that.

So I created two methods: the first was just a rename of this guy:

  /*
   * This method takes the exchange-specific time format and converts it
   * into a timestamp - msec since epoch. This is necessary to parse the
   * timestamp out of the exchange messages as the formats are different.
   */
  uint64_t unpackTimeFromEpoch( const char *aCode, uint32_t aSize )
  {
    // ...
  }

and the second was a much more efficient calculation of the milliseconds since midnight:

  /*
   * This method takes the exchange-specific time format and converts it
   * into a timestamp - msec since midnight. This is necessary to parse
   * the timestamp out of the exchange messages as the formats are
   * different.
   */
  uint64_t unpackTimeFromMidnight( const char *aCode, uint32_t aSize )
  {
    /*
     * The GIDS format of time is w.r.t. midnight, and a simple, 9-byte
     * field: HHMMSSCCC - so we can parse out this time.
     */
    uint64_t      timestamp = 0;
 
    // check that we have everything we need
    if ((aCode == NULL) || (aSize < 9)) {
      cLog.warn("[unpackTimeFromMidnight] the passed in data was NULL "
                "or insufficient length to do the job. Check on it.");
    } else {
      // now let's overwrite the hour, min, and sec from the data
      time_t  hour = (aCode[0] - '0')*10 + (aCode[1] - '0');
      time_t  min = (aCode[2] - '0')*10 + (aCode[3] - '0');
      time_t  sec = (aCode[4] - '0')*10 + (aCode[5] - '0');
      time_t  msec = ((aCode[6] - '0')*10 + (aCode[7] - '0'))*10 + (aCode[8] - '0');
      timestamp = ((hour*60 + min)*60 + sec)*1000 + msec;
      if (timestamp < 0) {
        // keep it to midnight - that's bad enough
        timestamp = 0;
        // ...and the log the error
        cLog.warn("[unpackTimeFromMidnight] unable to create the time "
                  "based on the provided data");
      }
    }
 
    return timestamp;
  }

At this point, I have something that has no system calls in it, and since I'm parsing all these exchange messages, that's going to really pay off in the end. I'm not going to have to do any nasty context switching for these calls - just simple multiplications and additions. I like being able to take the time to go back and clean this kind of stuff up. Makes me feel a lot better about the potential performance issues.

Oh... I forgot... in the rest of my code, I handled the difference in these two by looking at the magnitude of the value. Anything less than "a day" had to be "since midnight" - the rest are "since epoch". Pretty simple.

It works wonderfully!

Over the First Big Hurdle – Really Nice Feeling

Wednesday, August 11th, 2010

MarketData.jpg

This afternoon I can sit back for a minute and look at what I've been doing for the past several weeks as it's gotten to the point that it's tested against data from the exchange, and it's passed those tests. It's only one of about a dozen feeds that I need to handle, but it's the first, and that means that all the infrastructure work I've done - the boost asio sockets... the serialization... the unpacking of exchange data stream... all that is done. Now it's time to put the second codec in the system and see how well it maps to the system I created for one. I'm not really convinced that the design I have now will withstand all the other sources, unmodified, but it's a really good start, and I think it's close.

So I've run this sprint to get the first data feed done, and it's done, and now I find myself exceptionally tired. No surprise there... just a matter of when not if. I've been running on this for a long time without even the slightest break, but it's done now, and I can rest for a minute and then hit it again.

Well... there's my minute's rest... time to get back at it.

Flash Player with Hardware Acceleration Arrives – 10.1.82.76

Wednesday, August 11th, 2010

This morning I saw that Adobe finally released a hardware accelerated Flash player for Mac OS X. It's version 10.1.82.76, and it works for Safari and Chrome - the two I need it to work for. I'm hoping that I don't need it too much, but it's silly to think that there won't be cases that I do need it, so it's better to be up to date and waste a tiny bit of disk space than have an old, slow, plugin.

Initial Exchange Tests are Wonderfully Successful

Tuesday, August 10th, 2010

MarketData.jpg

This afternoon I was able to finally complete the initial exchange data feed tests on my new ticker plant infrastructure. The data was from a test file the exchange provides, but sent to my UDP receiver via a little test app that we have to simulate the exchange sending the data. I was not surprised to see a few mistakes in the logic - most notably in the parsing, but that's to be expected. Once I got those pointed out, the mistakes were obvious, and the fixes were trivial.

Then it just worked. Fantastic!

The speed was nice, but when you're testing on a single box, it's not really a fair test. I'll have to wait for the two test boxes that are supposed to be provided to me, and then I'll be able to make a much more real-world test. That will be interesting.

What I need to do next is to consolidate the codebase a little - the exchanges send the same data (so they say) on two independent UDP multicast channels, and we've created a dual-headed UDP receiver. We also have a single-headed one. There's too much that's similar, and so I want to consolidate them into a multi-headed UDP receiver and have it just work for from one to, say ten, inputs. The upper limit is really arbitrary, but I can't see them doing more than this anytime soon.

Anyway, it's back to the code, and then the new hardware for the full-up speed tests.

Giving Up on “Clever” Constructor Usage – Go Simpler

Monday, August 9th, 2010

OK, I decided today to give up my clever solution to parsing these exchange messages into normalized messages. It was just too nasty. The basics seemed to work well enough, but if there were a value I wanted to set that wasn't in the exchange data feed - like which feed this was, then I had a real problem. If I used the "tag" list constructor, the value needed to be set, and the setters are protected because I want these guys to appear immutable to all the other parts of the system. So I had to make a friend relationship.

But because each of these codecs might generate any number of these normalized messages, I'd have a ton of friend statements in each class. That's just not supportable. At some point in the future, someone is going to forget to add one in, and then it's a mess as they try to figure out what's going wrong and fix it.

It's far easier to realize that each normalized message has a complete, typed, constructor, and all I need to do is to parse out the values from the exchange data stream, and then call that version of the constructor, and we're done. Nothing fancy. Not all tricky. Just plain and simple code.

While the other approach might have been nice to figure out how to skip values in the tag list, or put in functors for callbacks to the different date/time parsers for the different exchanges, it was all a bunch of mental gymnastics as it really didn't make the code any easier to read, any faster, or any more supportable. It was coder ego, and that's something I just hate to see.

So I simply cut out all the crud I'd made, and went back to a far simpler scheme, and the code looks much better for it.

Google Chrome dev 6.0.472.25 is Out

Monday, August 9th, 2010

This morning they once again updated Google Chrome dev to 6.0.472.25 with the release notes just saying "UI Updates and Security fixes." It's all fine with me, as it's easy enough to update, but you'd think they'd take even 15 seconds to enumerate a few of the UI updates, or even list one or two security fixes. But such is not the case.

Still Hammering Away at that Exchange Data

Thursday, August 5th, 2010

Today, in addition to a few meetings, I've been hard at work trying to work all the messages from one exchange data feed into my new ticker plant. The previous version of this project had over 300 messages - one per exchange message. I'm going for a far more minimalist design: if it's not a price or a trade, it's in a free-form variant message, and that's going to really help me in minimizing the number of messages people have to understand and deal with.

Yet there are always twists.

Today I realized that there are messages from the exchange that don't update their sequence number. OK, maybe they aren't critical to the function of the ticker plant, but I didn't want to throw them out at the UDP receiver. So I had to adjust the methods on my data source to allow for ignoring the sequence number checks. It made things a little more complex, but in the end, it'll be a better system.

That's where I'm at these days - taking what I think is a good idea and applying a real problem to it and seeing where it needs to stretch and fit. I'm hoping that I can get this all done in a few more days and then get to the real-world tests and verify that things are working as desired.

I've got my fingers crossed...

Google Chrome dev 6.0.472.22 is Out

Thursday, August 5th, 2010

The relentless advance of Google Chrome has this morning deposited 6.0.472.22 on my little digital doorstep. The release notes are pretty sparse:

All Platforms

  • UI Updates
  • Stability Fixes
  • (Issue 49493) Fix some problems with SSL connections through HTTP proxies.

So maybe they have the Flash problem fixed in this build? Might be interesting to try it - just to see. In any case, it's relentless, but it's nice to see the progress. It's really quite impressive that it's overtaken Firefox so quickly.

Coda Notes 1.1 is Out

Wednesday, August 4th, 2010

I got another tweet from the Panic guys that they had updated Coda Notes 1.1 - and interestingly enough, the Safari Preferences panel handles all the updates for the extensions. It was a very pleasant surprise.