Oct 31

This week I wrote a post comparing O3D and WebGL.

Today I have finally spent some time playing with O3D and managed to implement some very simple applications.

Now that I have a clearer understanding of what O3D can and can’t do I have given some thought to the possibility of writing videogames in JavaScript. As I mentioned in my previous post I can’t see myself playing something like Fallout in a browser window. Nonetheless I can imagine simple multiplayer games, something like Monopoly or Risk, working this way.

I have developed quite a few JS applications that allowed users connected at the same time to interact with each other. It’s very simple, constant AJAX posts and gets with a server keeping the state of the interaction. Imagine something like GTalk integrated inside GMail.

This is all well and good when the interaction is limited to a few chat messages or coordinates of the mouse pointer on the screen, but multiplayer videogames have to shift a massive amount of data every second. When you play Gran Turismo online the position, speed and state of each player’s car must e synched across all the participants as often as possible. Add chat/voice data to that and you’ll soon realise that 30 players for one game calling your server at the same time to get and post data is just not manageable. Furthermore to ensure the timely delivery of the data to each client you are much better off pushing the data to the client rather than relying on it to call your server.

What O3D should add to its APIs is a DirectPlay alternative. Multiplayer support built straight into O3D. This way your JavaScript game will be able to establish peer-to-peer communication between all the clients without having to stress your servers. Simple socket communication giving the developers the ability to push data between all the peers connected.
Network support by being built inside the O3D plugin could also deal with all the annoying connectivity issues such as “punching” through NATs.

Without properly implemented network play I don’t think we’ll ever see 3D games flourish in your browser window.

Tagged with:
Oct 30

Maybe that’s a bit too harsh, maybe recursive query are not evil, it’s just the people who use them.

PostgreSQL LogoI spend quite a lot of time working with PostgreSQL users helping them optimise their queries. When I read that PostgreSQL 8.4 added support for recursive queries I knew that a whole new hellish chapter in my life would begin.

First off. What are recursive queries: (from PostgreSQL manual)

Recursive queries are typically used to deal with hierarchical or tree-structured data. A useful example is this query to find all the direct and indirect sub-parts of a product, given only a table that shows immediate inclusions:

WITH RECURSIVE included_parts(sub_part, part, quantity) AS (
SELECT sub_part, part, quantity FROM parts WHERE part = ‘our_product’
UNION ALL
SELECT p.sub_part, p.part, p.quantity
FROM included_parts pr, parts p
WHERE p.part = pr.sub_part
)
SELECT sub_part, SUM(quantity) as total_quantity
FROM included_parts
GROUP BY sub_part

These structures are commonly used in relational database. Just think about a threaded comment system for a blog or an industry classification for securities on multiple levels (financial data is what I’m most familiar with).

In this latter case you can image that you’ll hardly ever extract industry classification information by itself. It’s generally used as a sub-query to provide additional information about a security, a trade or what have you.

As I said earlier I have nothing against recursive queries per se. However, I can already see people out there creating monster-queries in production systems. The sort of monster query that needs to be executed 50 times a second, the one that just doesn’t work.

Storing and retrieving tree-structured data in SQL is one of my favourite questions in interviews. I always make a point of asking it. Not because it’s particularly challenging technically but because it will tell me a lot about the way the person I’m interviewing thinks about data.

The first part of the question is obviously do design a structure to hold threaded blog comments.

Whether you use a separate table to hold the relationship between nodes or a self-referencing parent id column in the same table I don’t really care. So long as you come up with an answer we can move on with the interview, because the answer to the next part of the question is what interests me.

I will now call your blog page with the ID from an element in your structure, any element. I want you to return instantly the ID of the root element for that branch of the tree.

- Root comment 1
   - Child 1.1
   - Child 1.2
      - Child 1.2.1
   - Child 1.3
- Root comment 2
   - Child 2.1
      - Child 2.1.1
         - Child 2.1.1.1
   - Child 2.2

I will call you with 2.1.1.1 and I want you to tell me 2, instantly. Feel free to change your database structure.

Their answer to this will tell me how they feel about de-normalisation and if they can think in those terms. We are talking about the daft requirements written by a product person who’s clearly gone quite mad. All he cares about is getting the data out quickly, nothing else.

Easiest de-normalised way out is to add a root id column in each comment row. It will make inserting new comments slower but it won’t require any recursion to go back to the top when selecting data.

If all you can come up with is recursive query I’ll be sorely disappointed. It’s cool and elegant but not nearly efficient enough for a high-availability production system.

Feel free to talk about recursive queries when I ask you this question, just remember to put the magic words “materialized view” in front of it. then we can talk.

Let this bet a warning to you. If I find a non-materialized/cached recursive query in your production code I will recursively kick you in the head.

Tagged with:
Oct 29

You may have read recently that Khronos is implementing something called WebGL. The objective of the project is to expose all of OpenGL ES calls to javascript. Thus allowing hardware accellerated 3d graphics within a browser.
Google has also been working on an alternative, called O3D.

Let’s first talk about the technical differencies between the two projects.

O3D and WebGL while both trying to bring accellerated 3D graphics to the web have taken two fairly different courses. As I mentioned in the introduction to this post WebGL’s plan is just to expose to JavaScript OpenGL ES 2.0 APIs. Whereas Google’s solution is based on a browser plugin.

If we think about this we’ll soon realise that WebGL depends entirely on JavaScript. JavaScript, as of today, is a fairly slow language. This point was made in a discussion thread on the O3D project website.

WebGL, being 100% dependent on JavaScript to do an application’s scene graph, is going to have serious problems drawing more than a few pieces of geometry at 60hz except in very special cases or on very fast machines. This means WebGL requires JavaScript to:

*) do all parent-child matrix calculations for a transform graph.

*) all culling calculations (bounding box to frustum or other)

*) all sorting calculations for dealing with transparent objects.

*) all animation calculations.

As an example the kitty demo in O3D is doing linear interpolations on 2710 floats to animate 170 transforms. The point is not that the artist that created the kitty should probably not have used 170 bones. ;-) Rather the point is it seems unlikely that JavaScript
will be able to do that anytime soon and if it can then just add more than one kitty to pass its limits.

Also we have to keep in mind that not all hardware supports OpenGL ES.

O3D, By virtue of being a browser plugin written in C++, so an additional (hopefully fast) abstraction layer on top of the GPU, allowed Google to define a new set of APIs to expose to JavaScript and keep us (the JavaScript developers) away from the hardware. O3D will take care of the interaction with either DirectX or OpenGL.

Furthermore Google has open-sourced O3D through its Google Code website. Which means we can all have a look at their code and participate in the project. This resulted in a lot of documentation being available. For a full overview of how O3D works check out the technical overview on the O3D project page.

Do you think that this is the making of a new “Standards war”? Both Google and Khronos are adamant that they are not competing. However I believe that ultimately only one project will come out as a standard. As the complexity of 3D web applications increases it is not feasible to write code for both “APIs”. The only question for me at this point is who will come out on top.

To answer this I would look at the audience of the two projects. OpenGL has been out in the wild for a long while and many developers of videogames, or general graphic application, are already familiar with the APIs and the way it works, therefore it would probably make sense for them to embrace WebGL.
Nonetheless O3D still stands a chance. For a very simple reason. It’s the web we’re talking about.

Frankly I can’t see myself playing a big videogame like fallout in a browser window anytime soon. These APIs will be used to enrich web application. Some examples are already coming out using O3D. Have a look at this Home Designer. Can’t you already see IKEA using it.
My point here is that we’re not likely to see game developers switch to the web. We’re much more likely to see web developers start working on games or application involving 3d graphics, and this is where Google wins.

O3D extends application JavaScript code with an API for 3D graphics. It uses standard JavaScript event processing and callback methods.

As a web developer I can keep writing JavaScript code as I’m used to without having to change the way I think to how a game developer does.

What do you think?

Tagged with:
Oct 28

Ever since Schmidt resigned from Apple’s board we all knew that a feud between the two companies was about to start.

Google had just launched Android, a Mobile OS. I’m sure we are all too aware of this.
Android wasn’t, and still isn’t a serious competitor for Apple’s iPhone. Google’s OS still has a long way to go to reach the “slickness” of the iPhone OS. Furthermore Google doesn’t have control over the hardware running its OS. Which means that the brilliancy of the OS can be completely overshadowed by the absurdity of the hardware. Honestly, some of the Android phones look like they have been designed by some boffin called Jenkins who was given complete freedom by their boss, Who should have instead said “No Jenkins you imbecile that’s not a phone. It’s crap. Do it again.”

I’m getting side-tracked. Let’s get back to the point.

Today Google announced Google Map Navigation for Android; and somehow I doubt it will make it to the iPhone. My guess is that Google is repaying Apple in kind for the whole Google Voice debacle. This is a serious blow and Apple will have some work to do to catch up with this.

More importantly Google Maps Navigation runs entirely off the net.
I have an iPhone with the Navigon app. It’s great but on my slim 8GB iPhone 25% of the storage is used for Navigon maps. With mobile internet connectivity becoming ever more ubiquitous this is definitely the way to go.

All I can hope for is that the rumor that came out a while ago about Google developing its own mobile phone is true. Then I might seriously consider giving up my iPhone.

UPDATE: AppleInsider reports that Google is in fact planning to port Google Maps Navigation to iPhone. If Apple approves the application, that is. Just PR or are they actually working on it?

“Apple is a close partner,” a Google spokesperson told AppleInsider Wednesday. “Millions of users experience Google Maps on the iPhone. We will continue to work with Apple to bring innovation, including Latitude and Navigation, to users but you’ll have to speak to Apple about availability.”

Tagged with:
Oct 27

Last week I wrote a rather long post asking for suggestions on how to cache and access a time series stored in an array in memory.

After some more research I have decided that the solution proposed by Uzair in his comment to the original post with some minor tweaks.

My originial idea involved creating a map in memory with one entry for each point in my series and then lookup the item requested in there.
This is very efficient when requests come in for a time which is in my index, if the point is not in there I’d have to run a binary search on the whole index. Which as Anon pointed out in his comment is still very fast.

if your ordered index is in-memory.

even if you had 1TB of memory (quite a lot), and each memory access took you 1 microsecond (slow),

each search would only take worse case of 40 accesses (2^40 = 1 trillion)
which would be 40 microseconds. this is not very long at all.

assuming some more reasonable ball-park figures of 4GB of memory, and
200 nanosecond access times, gives you

32 accesses * 200 nanos = 6 microseconds

this is over 150,000 searches per second.

The index will be a map of maps. Basically I’ll distribute a number of entries in my index at regular intervals. Each entry will contain a map of entries that preceded it in my time series.
Since I will know the first and last point in the series and the distribution of my regular entries *z* when a request *x* comes in I will be able to work out where is my next regular index entry *y*)

y = x – mod(x/z) + z

Once I have retrieved the map contained in my regular entry in the index I can proceed and lookup the value requested in there. If it’s not a point in my map I will still have to do a binary search but on a much smaller dataset – which I should be able to work on locally without having to rely on memcached over the network. The only “downside” of this solution is that I’ll have to make at least 2 lookups in my index.

Tagged with:
Oct 24
This is a problem I’ve been trying to deal with for a while now. In my case I’m talking about financial data. Most of it is – one way or another – a time series.
Take for example transactions. A position management system needs to be able to store millions of a transactions for a number of portfolios. Storing the data is not a problem for any relational database – The problem is querying it.
Financial data is, by its own nature, relational. This means, as far as I’m concerned, that you’d always want to store your raw data in a relational model without de-normalizing your data.
Now this is all good and well but when we need to access the transactions for a specific portfolio between the first of January 1999 and the 31st of December 2008 with all the related security information and prices and perform some analysis relational databases start to struggle.
Of course it is doable, but my argument against it is that CPU cycles used by your software to do the computation are less expensive than you database’s.
What I’m trying to achieve here is cache a time-series of transactions in a memory structure thus giving n clients access to it without having to constantly refer back to the database.
Client tells me what is the last transaction it knows about and all newer data is returned from the structure in memory. Thing is, I want to do it without having to loop over my Array/Map of transaction and avoid wasting memory by duplicating data.
Here’s a possible solution I’ve been toying with today.
The idea comes from a rendering technique used in videogames called voxel-based rendering, specifically an old game called Outcast.
I’ll try and briefly explain what that is (at least as far as my idea is concerned):
Say you are trying to render a landscape. Voxel rendering makes this fairly simple and is achieved column by column. For each column, a maximum Y value was stored (in a Y-Buffer). The pixels of the column in question are filled in starting at the bottom of the screen, only if their Y value was greater than the one stored in the Y-Buffer. This rendering method made the process of removing non-visible parts of the scene very efficient and very easy.
Instead of caching array of transactions based on a time value of variable granularity we could just create a massive ArrayList of all the transactions for any period of time. While creating the array we should also create a HashMap (our Y-buffer). The hasmap will simply contain a transaction unique id as key and the Position in the array as value.
This way when the client calls the APIs with the latest unique identifier it has received we’ll just have to make a very quick lookup in our Y-Buffer for the array position and then use the subList method of the List interface to retrieve everything in the transaction array from the position to the end (size()))This is a problem I’ve been trying to deal with for a while now. In my case I’m talking about financial data. Most of it is – one way or another – a time series.

This is something I’ve been thinking about for a while. How can I cache and have nearly-instant access to any data point within the time series without having to splash out on expensive time series databases. I have an half cooked solution and decided to write this post to see if anybody out there has worked on a similar problem and has a better solution to share.

Specifically I’m trying to work with financial data. Take for example transactions. A position management system needs to be able to store millions of a transactions for a number of portfolios. Storing the data is not a problem for any relational database – The problem is querying it.

Financial data is, by its own nature, relational. This means, as far as I’m concerned, that you’d always want to store your raw data in a relational model without de-normalizing it.

Now this is all good and well but when we need to access the transactions for a specific portfolio between the first of January 1999 and the 31st of December 2008 with all the related security information and prices relational databases start to struggle. Of course it is doable, but if you can get the data out first CPU cycles used by your software to do the computation are less expensive than you database’s.

What I want to be able to do is build a cache of the flattened (de-normalized) data and make it available to n clients at the same time.

The obvious solution is to build a massive time-ordered array of all the transactions and store it in memory. Considering the potential size of the array something like memcached would be more appropriate.
Here comes the second problem. Assume a client calls your software with a couple of dates, you will be forced to loop over the whole array to find the chunk you need. Again, doable, but inefficient.

Array is definitely the way to go to store the data. What I need is an “index” which will tell me exactly where a specific transaction is stored in the array.

Here’s a possible solution I’ve been toying with today.

The idea comes from a technique used in videogames called voxel-based-rending and ray-casting. I’ll try and briefly explain what that is (at least as far as my idea is concerned):

Say you are trying to render a landscape. Voxel rendering makes this fairly simple and is achieved column by column. For each column, a maximum Y value was stored (in a Y-Buffer). The pixels of the column in question are filled in starting at the bottom of the screen, only if their Y value was greater than the one stored in the Y-Buffer. This rendering method made the process of removing non-visible parts of the scene very efficient and very easy.

rendering ray casting voxels

While creating the array we should also create a map (our Y-buffer). The map will simply contain a transaction unique id as key and the position in the array as value.

This way when the client calls our APIs with the last unique identifier it has received we’ll just have to make a very quick lookup in our Y-Buffer for the array position and this will point us exactly to what we need to return.

This could work, but it’s only a partial solution, or rather a solution for a very specific problem. What we really want is for the client to be able to hand in 2 date-time values (from and to).
We could create our index using time information. The problem is that transactions are not at constant time-intervals. Which means that if we are called with a time value that is not in our index we’d still end up looping over the values around the closest point to find the position of the first element in the series.

An alternative would be to build our index using the maximum precision allowed. say an index of milliseconds where the last element position in the array is repeated in the index until a new one appears. Doable but very memory consuming.

This is as far as I’ve gone. Any other ideas out there?

UPDATE: follow-up article

Tagged with:
Nov 27

The Register, among many other news sites, reports that UK TV giants BBC, ITV and Channel 4 are to launch an on-demand video streaming service sometime in 2008.

Details are scarce in today’s announcement, but we’re promised “an exciting collection of over 10,000 hours of the very best of the UK broadcasters’ current and archive programming”. We’ve known about the project, codenamed “Project Kangaroo”, for some months now. The launch name hasn’t been revealed yet.

Will they get it right this time?
I’m perfectly ok with free streaming and pay for download/rental – one question though, are they finally going to shunt DRM protection?

I’d like to think the BBC has learned something from the verbal abuse it’s taken after the iPlayer was launched – or perhaps they’ll just do as they please and throw some rubbish like this at me:

14. Does Napster work with iPod?
Napster would like to work with your iPod, but Apple has chosen to keep both the iPod and iTunes closed off from Napster and every other digital music service. Napster’s philosophy is different. A Napster subscription gives you more ways to discover and enjoy music on more players. For a list of Napster-compatible players, click here.

Tagged with:
Nov 27

After much anticipation and hype the Gdrive seems to be on its way, or so the WSJ reports.

A Google spokeswoman declined to comment on any specific online storage plans beyond what it already offers as part of its email and other services. But she said in a statement that “storage is an important component of making Web [applications] fit easily into consumers’ and business users’ lives.”

Most companies, from small businesses to big giants are moving their environments online to make documentation/presentations or whatever else may be needed available to their employees, wherever they may be whenever they want.

As I said in a previous post Google is pushing its online productivity suite and a shared online storage could definitely give an additional boost to the entire system.
The online storage is one of the few reasons why I use .Mac, the second rationale behind the choice is that the interface is just brilliant, the iDisk is mounted as a file system and directly accessible from my Finder.

In my opinion if Google really wants to make the Gdisk a must have for small/big businesses a client software to access the data is vital – not because it works better, but because it is a step final users have to go through to get used to online storage solutions. Most people don’t, and won’t for a while, use Writely or Google’s new PowerPoint-ish software – they’ll keep creating documents in their local environment and the sensation of accessing a local drive to save their work will make them feel somewhat more secure.

For its office components to attract big businesses Google still has do a great deal of work on the corporate accounts handling side – being able to organize accounts in groups and set different access permissions on a Gdisk’s folders would be a great start.
Another useful additional feature, which as I understand is due sometime soon, is offline availability of the applications. An internet connection is not always available and an entire company can’t just stop working because IT people in the basement are messing around with routers.

Having said that it’s not only functionality-related issues Google has to address but also privacy and security questions. If they want more of our data to be stored on their servers, and with Gdisk it wouldn’t only be images and documents but all sort of data we may not want other people to see, we expect Google to have some pretty satisfactory answers ready – Especially when we’re talking about reserved and potentially vital information its business customers save in the cloud.

Tagged with:
Nov 26

Another post about my experiences with startups.

The one important thing I have ascertained about programmers during my career is that good ones are hard to find. Furthermore skillful developers tend to be ego-maniacs (I am no exception). The people generally portrayed in films as shy “nerds” are really expansive, loud and boastful persons. After all why shouldn’t they be; a startup’s most important assets are its people, and developers are a vital part of the organism. On the other hand it is also true that everybody is important but nobody is necessary.

In all the startups I’ve worked for, particular emphasis was put in the recruitment process, especially whilst hiring members of the initial core team. Which doesn’t mean only finding smart competent people, but also making sure that they’ll fit in with the rest of the team. Therefore it is very important to have every member of the initial team meet the candidate and make sure that they will be comfortable working with them; even people from different departments, marketing directors should meet programmers before an offer is made.

The other thing you have to make absolutely sure of is whether your newly-hired programmer can accept the technical leader’s style. The manager/CTO (call it whatever you want) has to be flexible, but at the end of the day he/she is still running the show and you can’t really afford to have a small team destabilized, especially when the disturbance undermines the leader’s authority.

I have had to interact with quite a few managers, each one with a different approach to the development process. The two most common and distinguishable modus operandi are certainly the autarchic and the unconstrationist (new word I just came up with).
The autarchic wants to be in full control every step of the way and put a two cents in every decision. The “libertine”, on the other hand, will take care of the big picture and leave the individual programmers to make decisions regarding the piece of functionality they have been assigned.

Neither attitude is wrong. However, I generally adhere to the more liberal approach, hence the title of the post. Being in charge of something every step of the way certainly helps prevent bugs from being introduced, if not because of a CTO’s superior experience because two brains are generally better than one. Anyhow if you try to be involved at every level of the development, from the requirements gathering and analysis to the practical development you’ll quickly end up being overwhelmed with work and with a crew perhaps not prepared to scale and be in charge of new hires themselves.

Contrarily leaving developers some independence in their restricted realm helps boost you team’s morale and prepares a normal programmers to be in change of somebody in the future as the company grows. Admittedly this approach will leave the whole system more exposed to potential bugs, introduced either for a technical mistake or lack of wide-angle-view-to-future-developments of the programmer in charge. The second drawback of this method is that you’ll most likely end up with a code library written with very different styles, hence harder to maintain and get used to for new people. Be that as it may, I still stick with “Celebrate Diversity”.
There’s always going to be a better tool or programming style than the one used when developing something. However, asking a proud programmer to change his code and do whatever you asked for exactly your way is worse than a punch in the guts.

As I said before neither approach is wrong and it’s purely a personal decision of the person in charge. It is a very difficult balance to strike. Ego-feeding is good, keeps the spirits up and developers are more likely to work harder and better. Unfortunately, programmers are human and as you leave somebody in charge of a single piece of functionality there might be nobody to find that stupid bug which could have been caught in a second by an additional brain.

Tagged with:
Nov 25

I was invited a few months ago to test the BBC iPlayer. I quite liked the idea and I’m very interested in everything streaming. I also tested Joost and Zattoo.

Unfortunately when the BBC decided to send me the invitation I had a Mac laptop and my computer at home was running Vista, !@”#$. Obviously the player doesn’t work with Mac OS. I wasn’t, however, expecting the application not to work with Vista. When I tried to activate the application I was greeted by an error popup telling me that the system works only with Internet Explorer on Windows XP. Fair enough.

iPlayer web interfaceI have now switched back to good old XP and am ready to test this player. Still no Firfox, I opened IE and logged in the BBC site with my beta account. Beautiful web interface, which works fine with Firefox too. After installing the small application an icon appears in the systray which is called: “Your Library”. Say what? I thought all BBC content was part of my library and I just had to click on any video to have it streamed to me instantly.

Apparently not. Opening the “Library” just says: you have nothing. Ok, so back to the BBC website with my newly installed IE plugin. Click on the new episode of Little Britain and right away the site told me that the video was being downloaded. Again, my only reaction is “Say what?”. So back to the library window, which is not even an application but a small popup running the IE engine with the BBC plugin to access your system information. This bright pink window is telling me that a 300 MB video is being downloaded and I had 500 MB of space on my hard drive allocated for the library.

My video is now here, excellent, click on play now. Another small IE-powered popup opens and, disguised under a customized interface, Windows Media Player starts playing the video, a bit slow though, but you can’t expect much from WMP. Oh yeah, almost forgot, my license for the video expires in 3 days then it’s a useless 300 MB file.

Now I don’t pretend to know any better than the BBC people working on this. They must have thought it through quite thoroughly. I do have a few questions though.

  1. Only windows XP and IE? Ever heard of flash? YouTube? Anybody? How about Mac users? Linux? Vista?
  2. Download a 300 MB file that I have to trash after 3 days? Planning to save on your Bandwidth anytime soon?
  3. Ever heard of streaming using P2P technology to save aforementioned bandwidth and offer more content? Seriously you should check out Joost, they started developing their application before you did.

Please, please have a look at Joost. Multi-platform, more content and less bandwidth usage because we stream to each other using BitTorrent‘s P2P technology. Maybe Janus Friis and Niklas Zennström will take pity on you and give you a small channel on their platform to share your content, if you ask nicely.

Tagged with:
preload preload preload