Node.JS Tutorial: What is Node.JS Good For?

October 11, 2011

This is the first post in a tutorial series covering Node.JS, from theoretics to practical implementation.

The word good is a subjective value term, especially when used in the context of programming, where comparisons between languages are often centered around what may be the “best” tool for one’s engineering goals with no absolutes assigned. However, Node.JS is a fairly good example of a well-written language and also a pretty good representative example of what’s happening in the software and technology industry as a whole – a giant move toward non-linear processing systems that mimic the complex processing found in nature and that better reflect modern life experience. It is thus not surprising that we are seeing a torrent of new programming technologies come out, from Scala to Node, to MongoDB, that are overturning the old and somewhat rigid order of things. They are  languages for the new world and for the programmers in it, who think differently than those from the past. Art may imitate life in this case, if you consider language design to be an art.

Node.JS is a good example of the new programming world. Node is a library, an application framework, and a webserver all rolled into one that runs off of Google’s V8 Engine, which is a Javascript interpreter built for Linux by Google. The V8 engine has enabled Javascript to be interepreted not just by a browser but also server-side. So point 1 for Node.JS, is that it is written in Javascript, a language known to pretty much every programmer and enables Javascript to be run on the backend of a webpage setup pretty easily.

Node is event-driven dynamic content serving and has asynchronous I/O. A event-driven dynamic content serving system means that, as a webserver, it handles connections without starting totally new processing threads between the client and itself. So Apache, which is not event-driven, keeps connections open in the form of a thread stored in memory to a particular client. Thus Apache itself, and the computer it runs on, can have problems scaling if there are too many connections, usually about 1000 connections at once. It simply freezes. There are in existence currently event-driven STATIC content serving servers, such as Lighttpd and NGINX. In fact, YouTube currently uses Lighttpd to serve up it’s static video(simply pull the video and display it). But for actual processing, actual scripting, something different was needed. Enter NODE.JS, and you have an dynamic event-driven webserver, one that takes commands and connections from the client as it is received, leaving no open processes. Fire away at it with all you got and it and the webserver can handle it.

Secondly, the webserver component, while important, is not all Node has to offer to improve efficiency and scalability. Node is asynchronous I/O, meaning it doesn’t parallelize it’s threads when it is running its functions. What does this mean? It means code continues processing after a function is called. Think about that for a moment – if you are a hardcore PHP programmer, this concept will be completely foreign to you – you can not wait for a function to finish before the interpreter moves onto the next line of code. It means the code will continue running while the function is processing. I know from my experience with PHP that this would result in me completely redesigning my code, and indeed in Node, functions are built inside functions, creating one long chain of function, in a function, in a function, in a function, etc. The reason this kind of processing works is because every function call in Node has a callback parameter, so there is no need for the parallelization that occurs in PHP, where your base code is stored in memory in the form of a thread, as the function being called runs in a separate thread. For huge web applications and services, this is majorly beneficial because it simply takes up less memory and, again, enables the web server/backend script combo to run on less memory overall, on less load, and reduces the chance the page will be frozen or lagged if too many hits, connections, or processes are happening at once.

The point is that Node has incredible benefits from a server load and business ( think electricity usage, RAM cost, number of servers) standpoint for large websites, which is why LinkedIn and the NYTimes are all switching to it from their current configurations.

In the old days, these type of processes, where you don’t do one thing at a time but many things, would probably be called chaos; it’s non-linear and it doesn’t make sense to simpletons. But these processes are actually carefully crafted organized chaos. The processes are diffused procedures.  This type of thinking change is a step forward, and it happens all the time. Node.JS is a step forward similar to the many step forwards before it.

Thanks to the folks at #Node.JS on FreeNODE.

Advertisements

On Herman Cain

October 10, 2011

I have a lot of free-time right now as I wait for my job begin and one of the ways I have been spending it (in addition to surveying Philadelphia for any aquatic activities it may offer such as kite surfing) is by studying the 2012 Republican field and the rise of Herman Cain. So who is  Herman Cain? Is he just a flash in the pan or a true force to be reckoned with? And what pray tell is his relationship to the GOP establishment?

Herman Cain was born to an extremely poor black family in Georgia. His dad held three jobs at one point, including as chauffeur for the CEO of Coca-Cola. Herman was gifted in math and science and upon graduation from Moorehouse College with a bachelors in mathematics, worked for the Department of the Navy as a ballistics analyst(rockets), before continuing onto graduate eduction at Purdue in computer science courtesy of the Navy. After a short stint at Coca-Cola as a computer scientist, he moved to Pillsbury where he was put in charge of Burger King’s Mid-Atlantic region(Pillsbury owned BK at the time) and the region went from being the worst division in Burger King’s portfolio to the most profitable. It was a tremendous turnaround for the division. Cain then went on to run Pillsbury’s Godfather’s Pizza subsidiary and turned that around too. Eventually, Cain became the Chairman of the Board of the Federal Reserve Bank of Kansas and the head of the National Restaurant Association.

In the Republican field there is another turn around artist – Mitt Romney  – who was the CEO of consulting firm Bain and started Bain Venture Capital. We can see the false analogy and misleading credential-based contrast being set up for the general election: Obama, whose “turn around” strategies haven’t worked to a satisfactory level for many citizens, must be voted out to make room for someone who has demonstrably turned around failing businesses because such experience is similar to what is needed to improve the fortunes of the U.S. macro economy. The difference between Cain and Romney is that Romney was a turn around artist for big businesses and Wall Street establishment types and Cain worked primarily in consumer facing businesses and was largely removed from such establishment activities during his time in the restaurant sector, or so Cain claims.

Lets talk about Cain’s supposed distance from establishment activities. It’s true that the man does have a populist background to some degree – he grew up poor, made his own way, and does have deep roots in consumer facing businesses where there is close customer contact and where the customer has a lot of choice(closer and more choice, than say, a consumer credit card operation from Chase Bank). On the other hand, Cain was the freaking Chairman of the Fed’s Kansas City Branch(Tim Geithner was the Chairman of the Fed’s New York Branch) for a year. Perhaps such a short stint indicates he was uncomfortable being in one of the most powerful and establishmentesque positions in America, but regardless he must’ve greased palms and played a few political games with the establishment to get there, or in other words, been in establishment circles – the same establishment now under attack by the grassroots political movements sprouting up all over the country. So while Cain may call himself an outsider, it’s pretty clear that he isn’t, and it’s pretty clear he was once a member of the group that is currently being targeted by both Republican(Tea Party) and Democrat(Occupy Wall Street) activists. The “elite.”

Whatever you think about his time at the Fed, there are more recent examples of Cain colluding with members of the establishment, or the “elite.” In fact, The Koch Brothers themselves have funded Cain since his entry into politics.

“Cain held an official position in the Koch-funded group Americans for Prosperity: Dating back to 2005, Cain led Americans for Prosperity’s new “Prosperity Expansion Project.” The position allowed Cain to barnstorm the country, giving speeches, holding town halls, and sharpening his skills for an eventual presidential bid.

Cain’s campaign manager is the former president of Koch-funded Americans for Prosperity Wisconsin chapter: Prior to becoming Cain’s campaign manager and chief of staff, Mark Block served as the president of Americans for Prosperity’s Wisconsin chapter. At the same time Block was serving in that position, he is credited with “talk[ing] Herman Cain into running for president”. As AFP-Wisconsin president in 2006, Block even tried to convince Cain to run for president in the 2008 election because of the former pizza executive’s rousing speeches at Americans for Prosperity events. Block has a history of electoral dirty tricks and once fined $15,000 for violating Wisconsin election law.

Cain attended the Koch Brothers’ private biannual meeting in Palm Springs: In January, the Kochs hosted one of their biannual meetings of top corporate and political figures in order to coordinate strategy and raise money for the conservative movement. Cain was among the small group of conservative politicians invited to attend.

Cain traveled to Wisconsin in support of the Koch-funded union-busting bill: During the apex of the fight in Wisconsin over Gov. Scott Walker’s (R) union-busting bill this spring, Cain traveled to the Badger State to support the conservative power-grab, speaking at a rally in February. The Koch brothers were major players in Wisconsin’s anti-union push.

Cain headlined a Koch-funded anti-climate rally in New York: As other presidential candidates focused on glad-handing with voters in Iowa and New Hampshire, Cain took time out in June to travel to New York and headline a Koch-backed anti-climate rally. The rally, held by Americans for Prosperity, protested New York’s involvement in the Regional Greenhouse Gas Initiative, an important project to fight global warming that has been long-opposed by the Koch Brothers.

Cain was a featured speaker at the Koch-funded RightOnline conference: Cain has been a featured speaker at RightOnline, the Koch-backed conservative conference, for the past twoyears.” ThinkProgress

The Koch Brothers, in other words, are HUGE on Cain and have had a long standing and financial relationship with him for several years now. Whether or not Cain is a defender of the little guy, or understands the “average joe’s needs” as a result of his business stint in retail America, his relationship with the Koch brothers must call into question who Cain actually represents or will represent if he wins the presidency: the citizens of the United States or the Koch Brother billionaires and those similarly-minded to them, whose interests are anathema to the common man according to the grass-roots activists of both parties. In other words, those supporting Cain for his populism and down to earth, honest-to-goodness,  rags-to-riches American success story, his brutal honesty, and his outside the beltway background, are simply supporting a show puppet for the very people they are trying to avoid voting for.

As the GOP is currently split between the Tea Partiers and the old guard of the GOP, the latter just don’t seem to be thrilled by Cain’s ascent. Cain’s Communications Director, a 25-year old from Louisiana State U, recently left the campaign to go work on the campaign for the Republican candidate for Mayor of Los Angeles. Cain recently hired a veteran public affairs director for the Pentagon to replace her. Such departures during the meteoric rise phase (Cain is 20 points ahead of any GOP Candidate in the Republican Primary and beats Obama by 2 points on a national comparison)  of a candidacy are pretty rare, and while the reason for the departure was “personal reasons,” speculation is abound that the GOP establishment basically pulled her from the Cain campaign and offered her a position somewhere else, paying more, and with more “opportunity.” How could a 25 year old say no to the GOP Establishment? Additionally, GOP establishment luminaries such as Rush Limbaugh and others have lashed out at Cain recently:

“[Charles] Krauthammer, in an appearance on Fox News, said Cain might siphon votes away from someone such as Rep. Michele Bachmann, R-Minn., but he would not be a major factor in the race.

‘I like the guy, but his candidacy is for entertainment,’ he said.

Rove, also during an appearance on Fox News, referred to Cain as the ‘talk radio guy in Atlanta’ and said he could not compare with someone such as Mike Huckabee, who has served as a governor and lieutenant governor in Arkansas.”

Cain is here to stay though. Herman Cain may be the only hope the establishment GOP has to win the race because he can siphon black voters away from Obama and weaken his numbers. He’s certainly trying:

Q:Before you announced your campaign, you said that the liberal establishment is scared that “a real black man might run against Barack Obama.” Are you suggesting Obama isn’t really black?

Cain: A real black man is not timid about making the right decisions, that’s what I meant. Look, I’m not getting into this whole thing about President Obama. It is documented that his mother was white and his father was from Africa. If he wants to call himself black, fine. If he wants to call himself African-American, fine. I’m not going down this color road.

Q:But you’re saying he’s not really a black man.

A: Not in terms of a strong black man that I’m identifying with. I identify with a strong black man like Martin Luther King Jr., or my dad, Luther Cain Jr., who didn’t have a lot of formal education, but he had a Ph.D. in common sense.

I think a VP-slot is not out of the question for Cain. I think a Romney/Cain nomination could carry the country by weakening Obama’s appeal to minorities and by uniting the Tea Party and GOP Establishment factions. I can’t see Cain being president, but if the GOP is smart and if its radical and establishment factions can come together – we could see a Republican candidacy take the White House.

Lets hope not or we will all suffer something worse than the Bush years.

“Barack Obama you said you plan to raise 1 billion dollars for your campaign, well the American people are gonna raise some Cain to defeat you” – Herman Cain in Florida.


%d bloggers like this: