Thursday, January 20, 2011

Open Social Network

Facebook. Social Networks. These words keep popping from everywhere these days. We spend more and more of our time online, looking at what our peers have to say. According to recent reports, Facebook tipped Google as the most frequently visited site in the world[ref needed]. Many applications are starting to become "social", i.e., generating their data from your network of friends. For example, what restaurants your friends eat at rather than some random people might be of more interest to you. In the near future, most applications would incorporate the social aspects, so it becomes important that you as a user are a part of a social network to take advantage of it.

Of course, this means that you put more and more of your personal information online to take advantage of the system. Hence, it is important that your information is well guarded, and that you have control over who can access that information and in what ways. As quite famously said, you are Facebook's product, not customer[ref].

In the current scenario, Facebook is the clear leader in terms of number of users[ref needed], at least in the United States. A monopoly of this sort is not good for the end user. The biggest asset of a social network is its users - and not the services it provides. You don't join the social network which has the best photo sharing application, or the best privacy practices; you join the one which has most of your friends on it already. Thus, even if you don't necessarily like the social network you are on, you may be forced to be on it since you don't want to lose contact with your friends. This means that your social network provider can afford to keep the user's best interests as secondary and its revenue generator's interests primary once it has enough users.

If we look at other similar technologies of the past, we can see that the situation is different. Email and telephone are two standing examples. You may choose any email provider you want, and still be able to communicate with anyone who has an email on any server in the world. Heck, you can even run your own mail server if you do not like anyone's service. Google changed the email space by offering large amounts of storage and a clean interface (subjective), which prompted others to follow suite. In telephony as well, you may communicate to any telephone user regardless of who the provider is. However, telephone companies do give you an added incentive to join their network by allowing free calls to anyone in the same network, which means you are likely to join the network which your friends have joined. Such incentives are unheard of in the realm of email (although depending on future net-neutrality laws, this might change - however that is the subject of another big discussion).

The ideal situation for the end-user (you) is to have an open communication model similar to email, where you may be able to connect to users on any social network, with most features intact. The primary driver of the market would then be the quality of service offered by the providers, and all shall be well. If you don't like the privacy options of Friendster, join Hi5. If you don't like the interface of Orkut, join Facebook.

Hopefully Facebook's new message system and Google's Opensocial are steps in the right direction. There are also applications like Yoono and HootSuite which allow you to monitor all your social networks from one place. However, a tightly-integrated system like email is still desirable.

Wednesday, September 23, 2009

Memory Consistency in practice

As an architect going over memory consistency models it is quite easy to lose focus and direction as to how/where real programs are exposed to these. Some material which seems useful (warning : haven't read/seen the material in entirity yet) :

http://msdn.microsoft.com/en-us/magazine/cc163715.aspx

Thursday, September 3, 2009

yipikaye, mothafucka

This is something I could have sweared my life upon, and yet I would have been wrong. Exhibit:

C/C++

printf("%d\n", -1/2);


Python

print "%d", -1/2

What do you expect to be printed out? 0? -1? Turns out, C prints 0 for this, and Python prints -1. I explored more and found this: C assumes the remainder to be the same sign as the dividend (after making the divisor non-zero - otherwise we'd get different answers for -1/2 and 1/-2).
Python always assumes it to be positive. My entire life, I had thought quotient was always floor(a/d), and hence the remainder would always be positive.

The repercussions? Well, this brings a "discontinuity" (I know there's a proper mathematical word for such functions, but lets work with this) in the quotient. 1/2 is also 0, and -1/2 is also 0 because we changed the sign of the remainder. If remainder was always positive, then the function would have been "continuous". How does this affect you? Suppose you were to write a heapify_up function for a binomial heap implemented on an array, where you started at some index, and worked your way to the root. Everyone knows that for a parent node at index i, the children are at 2*i+1 and 2*i+2. Or, for a child j, the parent is at (j-1)/2. Since you want to move up through the parents until you reach the root, you write a loop :

for (j = idx; j >=0; j = (j-1)/2)
{
blah
}
Pretty clever, eh? As soon as j becomes negative, you break out of the loop. Except, j never becomes negative in C. When j reaches 0, (j-1)/2 evaluates to...drum rolls..0! An effin' infinite loop!

Death 1, Me 0

Saturday, June 27, 2009

Finally, arriving somewhere that's here

Topic of the week : Pipelining, von Neumann, et cetera

Ok, this is easy. Ever went to subway for a dinner when you're hungry and that paper is due next week and you didn't like cooking anyway? The queue is long, and the superefficient workers still manage it somehow. The first one asks for your order and gets a bread. The second one puts the meat and the cheese inside and puts it in the oven. The third one puts in lettuce, tomatoes and the sauces for you, and you pay to the fourth one. Now, one way could be to do this entire process just for you, then for the next guy and then for the next guy. Of course, that'd take almost four times as much time as when every worker works on a different order at the same time. You don't want that.

We don't either. This is the basic principle behind most modern processors. Multiple instructions are processed at the same time, rather than one by one. While One instruction is being fetch, a previously fetched instruction is decoded, a previously decoded instruction is being executed, the result of a previously executed instruction is written back to the memory if needed, and another instruction writes its result to a register in the processor. Thus this makes it a five-stage pipeline, with the stages being instruction fetch (IF), instruction decode (ID), execute (EX), memory (MEM) and write back to register (WB). Ideally, this machine would run at 5 times the speed of another CPU which does all this one at a time.

Now, if you are with a girl you are dating, you may like to see what fillings she asks for, and you may ask for the same and say, "hey, we're so similar!". One way is to let her order while you wait in the line, and when she finishes and pays (aren't you a stupid boy! well, what were you doing taking a girl out to subway anyway :P ) and comes back you go ahead and order yours. Another way is to follow just behind her and see what she orders and you order accordingly. No unnecessary waiting! Such a situation is called a "dependency" and this measure to use the result of her action even before she has finished is called forwarding.

Of course, not everything is perfect. Maybe someone wants his sandwich baked which takes more time, while you standing behind him don't. So you'd like to go ahead, but this would break the pipeline. So you and everyone behind you have to "stall".

Well some chap named Tomasulo came along and said, ok, you can go ahead. you don't have to wait for him if you're not depending on him. So you're happy and all. But the other guy goes, hey, I came before him, why is he leaving before me? So you may have to wait before you pay and leave, i.e., finally, you go out in the order you came in, but in between you are free to execute in any order. This ordering of instructions is kind of important in most situations for programs as most of the times they are written assuming such an order.

Some people just don't like this. I mean, this kind of thing, where you have to stand in a line and wait for your turn when you don't give a rat's ass about the guy before you. This kind of architecture is called a von Neumann architecture - where you fetch instructions one by one from a stream and then execute it. I mean, what if you have a hundred people waiting in the line? You can increase the number of workers, but if everyone has to wait in a single line to come to them, that's just a waste.

It just so happens that this process of bringing in instructions one by one, cute as it is, is not infinitely scalable. The memory is not as fast as the CPU, and can't keep up. What's with all this bringing in and storing back? Why can't you just do the work where your instructions are?

Well, you could have the workers come to them. Like in a restaurant, get it? Well, yeah if the waiters cook at the table, that'd be pretty similar to it. These are called dataflow architectures; small processing elements reside where the memory is, and everything gets done in situ. Why dataflow? well you're not worried about a stream of instructions, which would be control flow - rather, you just worry about from whom you want to get the data, i.e. what are your friends getting, who decides what you order?

Too much for one sitting, eh? adieu.