Node http://rickgaribay.net/category/53.aspx Node en-US Rick G. Garibay rickgaribay@hotmail.com Subtext Version 1.9.5.176 Visual Studio Live Redmond &ndash; 8/18 to 8/21 http://rickgaribay.net/archive/2014/08/11/visual-studio-live-redmond-ndash-818-to-821.aspx <div align="center"> <h1>The Goods... </h1> <br /> Thank you Redmond, 1105 Media, Microsoft, fellow speakers and all attendees for a great show. I had a blast! <br /> <table><tbody> <tr> <td><iframe height="400" marginheight="0" src="//www.slideshare.net/slideshow/embed_code/38229557" frameborder="0" width="476" marginwidth="0" scrolling="no"></iframe> <br />Code: <a href="https://github.com/rickggaribay/neurl">https://github.com/rickggaribay/IoT</a> </td> <td> </td> <td><iframe height="400" marginheight="0" src="//www.slideshare.net/slideshow/embed_code/38229551" frameborder="0" width="476" marginwidth="0" scrolling="no"></iframe> <br />Code: <a href="https://github.com/rickggaribay/neurl">https://github.com/rickggaribay/neurl</a> </td> </tr> </tbody></table> </div> +++ <p> </p> <p>I’m thrilled to be speaking at VS Live Redmond next week. The show starts on Monday August 18th and goes through Thursday the 21st on Microsoft campus in Redmond, WA. </p> <p>Events in Redmond a<a href="http://bit.ly/RDSPK10"><img title="RDSPK10 (1)" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; margin: 15px 10px; display: inline; border-top-width: 0px" border="0" alt="RDSPK10 (1)" align="left" src="http://rickgaribay.net/images/rickgaribay_net/WindowsLiveWriter/VisualStudioLiveRedmond818to821_E9B6/RDSPK10%20(1)_3.jpg" width="184" height="154" /></a>re always a special treat as it gives everyone a chance to see the campus, interact with product team members and as always, meet and hang out with some of the best, most recognized speakers in the industry like Ted Neward, Michael Collier, Brian Noyes, Eric Boyd, Rachel Appel, Miguel Castro, Rocky Lhotka, Andrew Brust- the list goes on.</p> <p>I’ll be delivering two Azure focused presentations on the Internet of Things and API development with NodeJS.</p> <p>Since there is only so much space available for the abstracts themselves, I thought I’d elaborate a bit on what you can expect from each session in this short post. You can find more details about both talks on the VS Live Redmond <a href="http://bit.ly/RDSPK10" target="_blank">website</a> or go directly to the abstracts by following the links below.</p> <p><strong>From the Internet of Things to Intelligent Systems: A Developer's Primer</strong></p> <p>In this talk, I lay the foundation for IoT and why you, as a developer should care. I’ll show off a handful of devices ranging from Arduino, Netduino and Fez Spider and demonstrate a number of common patterns currently in the wild including default communication, brokered and service assisted. We’ll explore the challenges that exist today in supporting commands, notifications, inquiries and telemetry. I’ll then spend some time giving you an in-depth tour of Reykjavik, Microsoft’s code name for its reference architecture focused on delivering highly scalable messaging fabrics for modern IoT solutions. </p> <p>We’ll take a look at the reference architecture and how it maps to components on Microsoft Azure. I’ll then demonstrate what a first-class Reykjavik device looks like and demonstrate live telemetry and commands for an end-to-end tour of Reykjavik. I’ve been spending a lot of time with Clemens and team over the last several weeks so this promises to be an inside look at the reference architecture and general shape of things you're unlikely to find publically anywhere else.</p> <p>Learn more about this talk here: <a title="http://bit.ly/VSLRIOT" href="http://bit.ly/VSLRIOT">http://bit.ly/VSLRIOT</a> or follow the conversation on Twitter #VSLTH04</p> <p><strong>Building APIs with NodeJS on Microsoft Azure Websites</strong></p> <p>This is a talk that I’ve been working on for several months now and continues to evolve. As I discuss in my <a href="http://bit.ly/1nT4K6h" target="_blank">latest article in CODE Magazine</a>, it started off as a spike for teaching myself basic NodeJS and kind of evolved into a little project for work that needed a hosting environment. After exploring various options, Azure Websites made the most sense and this talk focuses on the key features and functionality of a little URL shortening API along with key ALM considerations like IDE, unit testing, continuous integration and deployment. </p> <p>I’ll walk you through each step I took in building this API from scratch and deploy it live to Azure Websites as well as show you some really cool things you can do with the Kudu console when things go awry (as they almost always do in a live demo :-)) </p> <p>More about this talk here: <a title="http://bit.ly/VSLRAPI" href="http://bit.ly/VSLRAPI">http://bit.ly/VSLRAPI</a> or follow the conversation on Twitter  #VSLW09</p> <p>If you plan on attending either of my sessions please stop by and say hi or after the talk. I hope to see you there!</p><img src="http://rickgaribay.net/aggbug/371.aspx" width="1" height="1" /> Rick G. Garibay http://rickgaribay.net/archive/2014/08/11/visual-studio-live-redmond-ndash-818-to-821.aspx Mon, 11 Aug 2014 23:38:01 GMT http://rickgaribay.net/archive/2014/08/11/visual-studio-live-redmond-ndash-818-to-821.aspx#feedback http://rickgaribay.net/comments/commentRss/371.aspx http://rickgaribay.net/services/trackbacks/371.aspx Visual Studio Live! Las Vegas http://rickgaribay.net/archive/2013/02/17/visual-studio-live-las-vegas.aspx <p> </p> <p>I’ll be <a href="http://vslive.com/events/las-vegas-2013/Speakers/Speaker%20Window.aspx?SpeakerId={E7CDD516-A07D-4FB8-A7B3-AA538E893EA7}&amp;ID={6EF8BE9C-3D36-4000-8879-02F12BDF2D2F}" target="_blank">speaking</a> at <a href="http://vslive.com/home.aspx" target="_blank">Visual Studio Live</a>!, March 25-29 in Las Vegas, NV <a href="http://bit.ly/VSLPKK14Reg">http://bit.ly/VSLPKK14Reg</a>.  <a href="http://vslive.com/events/las-vegas-2013/home.aspx?utm_source=AttendeeMktg&amp;utm_medium=Fax&amp;utm_campaign=VLSPK14" target="_blank"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="VSL13_Badge_See125x125" border="0" alt="VSL13_Badge_See125x125" align="right" src="http://rickgaribay.net/images/rickgaribay_net/Windows-Live-Writer/Visual-Studio-Live-Las-Vegas_AD06/VSL13_Badge_See125x125_3.jpg" width="129" height="129" /></a></p> <p>There are a ton of great sessions from fellow friends, MVPs and <a title="" href="http://neudesic.com" rel="">Neudesic</a> colleagues so this is sure to be a great show.</p> <p>I’ll be presenting the following sessions:</p> <ul> <li><a href="http://vslive.com/Events/Las-Vegas-2013/Sessions/Tuesday/T21--Build-Speedy-Azure-Applications-with-HTML-5-and-Web-Sockets-Today.aspx" target="_blank">Build Speedy Azure Applications with HTML5 and Web Sockets Today</a> </li> <li><a href="http://vslive.com/Events/Las-Vegas-2013/Sessions/Tuesday/T13--Chalk-Talk-Building-a-URL-Shortening-Service-with-Node.js.aspx" target="_blank">Chalk Talk: Beyond Hello World – A practical introduction to Node.js</a> </li> </ul> <p>SPECIAL OFFER: As a speaker, I can extend $500 savings on the 5-day package. Just be sure to use this link to register and use code <b>VLSPK14: </b><a href="http://bit.ly/VSLPKK14Reg">http://bit.ly/VSLPKK14Reg</a></p> <p>Hope to see you there!</p><img src="http://rickgaribay.net/aggbug/354.aspx" width="1" height="1" /> Rick G. Garibay http://rickgaribay.net/archive/2013/02/17/visual-studio-live-las-vegas.aspx Sun, 17 Feb 2013 19:32:12 GMT http://rickgaribay.net/archive/2013/02/17/visual-studio-live-las-vegas.aspx#feedback 1 http://rickgaribay.net/comments/commentRss/354.aspx http://rickgaribay.net/services/trackbacks/354.aspx PCSUG.org June Meeting Featuring Glenn Block on Node.js http://rickgaribay.net/archive/2012/05/16/pcsug.org-june-meeting-featuring-glenn-block-on-node.js.aspx <p style="text-align: center; margin: 0in 0in 10pt" class="MsoNormal"><strong style="mso-bidi-font-weight: normal"><span style="color: black; mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: text1"><span style="font-size: medium"><span style="font-family: calibri"><span style="color: black; mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: text1"><span style="font-size: medium"><span style="font-family: calibri"><a href="http://pcsug.org/Home/Events" target="_blank"><img alt="" src="http://pcsug.org/Content/Images/Logo.jpg" width="438" height="110" /></a></span></span></span></span></span></span></strong></p> <p style="text-align: center; margin: 0in 0in 10pt" class="MsoNormal"><strong style="mso-bidi-font-weight: normal"><span style="color: black; mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: text1"><span style="font-size: medium"><span style="font-family: calibri"><span style="color: black; mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: text1"><span style="font-size: medium"><span style="font-family: calibri"></span></span></span></span></span></span></strong></p> <p style="text-align: center; margin: 0in 0in 10pt" class="MsoNormal" align="left"><strong><font size="3">June 14th 2012 @ Microsoft Southwest District Office in Tempe, AZ</font></strong></p> <p style="line-height: 12.75pt; background: white" align="center"><span style="font-family: 'Calibri','sans-serif'; color: black; font-size: 11pt; mso-bidi-theme-font: minor-latin; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-ansi-language: da" lang="DA"><strong><font size="3"><font color="#ff0000">Registration is required. Please visit pcsug.org for more information and to register for this event</font>: </font><a title="http://pcsug.org/Home/Events" href="http://pcsug.org/Home/Events"><font size="3">http://pcsug.org/Home/Events</font></a><font size="3"> </font></strong></span></p> <p style="text-align: left; margin: 0in 0in 10pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: text1"><span style="font-size: medium"><span style="font-family: calibri">You asked for it, and here it is. </span></span></span></p> <p style="text-align: left; margin: 0in 0in 10pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: text1"><span style="font-size: medium"><span style="font-family: calibri">As a user group that is exclusively focused on distributed computing, the appeal of Node.js to a bunch of messaging guys is obvious. Node.js is <a href="http://rickgaribay.net/archive/2012/01/28/node-is-not-single-threaded.aspx">new, fascinating and seductive</a>. <a href="http://www.windowsazure.com/en-us/develop/nodejs/" target="_blank"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="windows-azure-logo" border="0" alt="windows-azure-logo" align="right" src="http://rickgaribay.net/Images/customcontent/b2bb896f0c63_D909/windows-azure-logo_thumb.jpg" width="240" height="90" /></a></span></span></span></p> <p style="text-align: left; margin: 0in 0in 10pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: text1"><span style="font-size: medium"><span style="font-family: calibri">After much excitement and buzz around Node.js in general and on Windows Azure in particular, PCSUG.org</span></span></span><strong style="mso-bidi-font-weight: normal"><span style="color: black; mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: text1"><span style="font-size: medium"><span style="font-family: calibri">  </span></span></span></strong><span style="color: black; mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: text1"><span style="font-size: medium"><span style="font-family: calibri">is thrilled to kick off the summer with Glenn Block, Senior Program Manager on the Node.js SDK for Windows Azure team.</span></span></span></p> <p style="text-align: left; margin: 0in 0in 10pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: text1"><span style="font-size: medium"><span style="font-family: calibri">Joining us from Redmond, <a href="http://twitter.com/gblock" target="_blank">Glenn</a> will be sharing the latest on what the Azure SDK for Windows Azure has to offer, whether you are new to Node.js development or a seasoned veteran.</span></span></span></p> <p style="text-align: left; margin: 0in 0in 10pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: text1"><span style="font-size: medium"><span style="font-family: calibri">In addition, our own Developer Evangelist, J. Michael Palermo will help kick things off with a discussion on what the back-end developer needs to know about HTML5 and Windows 8.<a href="http://nodejs.org/" target="_blank"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="node" border="0" alt="node" align="right" src="http://rickgaribay.net/Images/customcontent/b2bb896f0c63_D909/node_3.png" width="187" height="54" /></a></span></span></span></p> <p style="text-align: left; margin: 0in 0in 10pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: text1"><span style="font-size: medium"><span style="font-family: calibri">Below is the agenda and logistics- we hope you'll join us for a great opportunity to learn about what Node.js on Windows Azure has to offer as well as network and connect with other members of the Phoenix developer community.</span></span></span></p> <p style="margin: 15pt 0in 1.5pt; background: white" class="MsoNormal"><span style="font-size: medium"><span style="font-family: calibri"><strong style="mso-bidi-font-weight: normal"><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin">6:00 to 8:00 pm</span></strong><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin">: <span style="color: black; mso-bidi-font-weight: bold"><em><strong>"Unlock your Inner Node.js in the Cloud with Windows Azure"</strong></em> </span><em>with</em> Glenn Block, Senior Program Manager, Microsoft Corporation  </span></span></span></p> <p style="margin: 15pt 0in 1.5pt; background: white" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"><span style="font-size: medium"><span style="font-family: calibri">If I told you that you can build node.js applications in Windows Azure would you believe me? Come to this session and I’ll show you how. You’ll see how take those existing node apps and easily deploy them to Windows Azure from any platform. You’ll see how you can make <span style="color: black; mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"><span style="font-size: medium"><span style="font-family: calibri"><img style="background-image: none; border-right-width: 0px; margin: 0px 10px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" align="left" src="http://archive.oredev.org/images/18.3efb083311ac562f9fe800010787/GlennBlock.jpg" width="102" height="136" /></span></span></span>yours node apps more robust by leveraging Azure services like storage and service bus, all of which are available in our new “azure” npm module.  You’ll also see how to take advantage of cool tools like socket.io for WebSockets, node-inspector for debugging and Cloud9 for an awesome online development experience.</span></span></span></p> <p style="margin: 15pt 0in 1.5pt; background: white" class="MsoNormal"><span style="font-size: medium"><span style="font-family: calibri"><strong style="mso-bidi-font-weight: normal"><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin">About Glenn Block</span></strong></span></span></p> <p style="line-height: 12.75pt; background: white"><span style="font-family: 'Calibri','sans-serif'; color: black; font-size: 11pt; mso-bidi-theme-font: minor-latin; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-ansi-language: da" lang="DA"><font size="3">Glenn is a PM at Microsoft working on support for node.js in Windows and Azure. Glenn has a breadth of experience both both inside and outside Microsoft developing software solutions for ISVs and the enterprise. Glenn has been a passionate supporter of open source and has been active in involving folks from the community in the development of software at Microsoft. This has included shipping products under open source licenses, as well as assisting other teams looking to do so. Glenn is also a lover of community and a frequent speaker at local and international events and user groups.</font></span></p> <p style="line-height: 12.75pt; background: white"><font size="3" face="Calibri"><a title="http://codebetter.com/glennblock/" href="http://codebetter.com/glennblock/" target="_blank">http://codebetter.com/glennblock/</a></font></p> <p style="line-height: 12.75pt; background: white"><font size="3" face="Calibri"><a title="https://twitter.com/#!/gblock" href="https://twitter.com/gblock" target="_blank">https://twitter.com/gblock</a></font><font size="3" face="Calibri">    </font></p> <p style="margin: 0in 0in 10pt" class="MsoNormal"><span style="font-size: medium"><span style="font-family: calibri"><strong style="mso-bidi-font-weight: normal"><span style="color: black; mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: text1">5:30 to 6:00 pm:</span></strong><span style="color: black; mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: text1"><em> </em><strong>“What the back-end developer needs to know about HTML5 and Windows 8”</strong> with J. Michael Palermo, Senior Developer Evangelist, Microsoft Corporation</span></span></span></p> <p style="margin: 0in 0in 10pt" class="MsoNormal"><a href="http://rickgaribay.net/Images/customcontent/b2bb896f0c63_D909/image_3.png"><img style="background-image: none; border-right-width: 0px; margin: 0px 9px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" align="left" src="http://rickgaribay.net/Images/customcontent/b2bb896f0c63_D909/image_thumb_3.png" width="102" height="123" /></a><span style="color: black; mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: text1"><span style="font-size: medium"><span style="font-family: calibri">Understanding how client applications use and access data  is essential for structuring and providing data through services.  And just as back-end solutions evolve, so does the client.  In this session, you will see how a Windows 8 Metro Style application written in JavaScript and HTML5  is developed to access data via REST APIs and web sockets.</span></span></span></p> <p style="margin: 0in 0in 10pt" class="MsoNormal"><strong style="mso-bidi-font-weight: normal"><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"><span style="font-size: medium"><span style="font-family: calibri">About J. Michael Palermo:</span></span></span></strong></p> <p style="margin: 0in 0in 10pt" class="MsoNormal"><span style="color: black; mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: text1"><span style="font-family: calibri; font-size: medium">J. “Michael” Palermo IV is a Developer Evangelist with Microsoft.<span style="mso-spacerun: yes">  </span>In his years prior to joining Microsoft, Michael served as a Microsoft Regional Director and MVP.<span style="mso-spacerun: yes">  </span>Michael has authored several technical books and has published online courses with </span></span><a href="http://www.palermo4.com/page/Pluralsight.aspx"><span style="color: black; mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: text1"><span style="font-family: calibri; font-size: medium">Pluralsight</span></span></a><span style="color: black; mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: text1"><span style="font-size: medium"><span style="font-family: calibri"> on HTML5 technologies.<span style="mso-spacerun: yes">  </span>Michael continues to share his passion for software development by speaking at developer events around the world.</span></span></span></p> <p style="margin: 0in 0in 10pt" class="MsoNormal"><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"><span style="font-family: calibri; color: #0000ff; font-size: medium"><a href="http://www.palermo4.com/" target="_blank">http://www.palermo4.com</a></span></span><font size="3" face="Calibri"> </font></p> <p style="margin: 0in 0in 10pt" class="MsoNormal"><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"><span style="font-family: calibri; color: #0000ff; font-size: medium"><a href="http://twitter.com/palermo4">http://twitter.com/palermo4</a></span></span></p> <p style="line-height: 12.75pt; background: white"><font size="3" face="Calibri"></font></p> <p style="line-height: 12.75pt; background: white" align="center"><span style="font-family: 'Calibri','sans-serif'; color: black; font-size: 11pt; mso-bidi-theme-font: minor-latin; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-ansi-language: da" lang="DA"><strong><font size="3"><font color="#ff0000">Registration is required. Please visit pcsug.org for more information and to register for this event</font>: </font><a title="http://pcsug.org/Home/Events" href="http://pcsug.org/Home/Events"><font size="3">http://pcsug.org/Home/Events</font></a><font size="3"> </font></strong></span></p><img src="http://rickgaribay.net/aggbug/339.aspx" width="1" height="1" /> Rick G. Garibay http://rickgaribay.net/archive/2012/05/16/pcsug.org-june-meeting-featuring-glenn-block-on-node.js.aspx Wed, 16 May 2012 22:43:40 GMT http://rickgaribay.net/archive/2012/05/16/pcsug.org-june-meeting-featuring-glenn-block-on-node.js.aspx#feedback http://rickgaribay.net/comments/commentRss/339.aspx http://rickgaribay.net/services/trackbacks/339.aspx Building Speedy Azure Applications with HTML5 and Web Sockets Today http://rickgaribay.net/archive/2012/03/29/building-speedy-azure-applications-with-html5-and-web-sockets-today.aspx <p>I had the pleasure of presenting at Spring DevConnections today in Las Vegas and as promised, below are the samples for each of my demos.</p> <p>To recap. WebSocket brings full-duplex, bi-directional TCP sockets to web, desktop and mobile applications, introducing an alternative to XHR and long-polling, particularly when latency is a primary focus. What makes WebSocket so significant to developers in addition to providing a direct, socket-based connection is that it is standardized by both the IETF Hybi working group and W3C which has brought wide industry support across both browser vendors implementing the client support and platform vendors providing support for building WebSocket servers. </p> <p><a href="http://rickgaribay.net/Images/customcontent/c1f79a9417a5_B3EF/image.png"><img style="background-image: none; border-right-width: 0px; margin: 2px 8px 2px 2px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" align="left" src="http://rickgaribay.net/Images/customcontent/c1f79a9417a5_B3EF/image_thumb.png" width="244" height="133" /></a>Microsoft has been an early champion of the WebSocket protocol, sharing some early investments via HTML5 <a href="http://html5labs.interoperabilitybridges.com/" target="_blank">Interoperability Labs</a> website and maintaining that investment with support for the WebSocket protocol announced at //Build 11 which introduced WebSocket support to Windows 8, Windows Server 8. .NET 4.5 and IE 10 Developer Preview based on the hybi-10 specification.</p> <p><a href="https://www.windowsazure.com/nodejs" target="_blank"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" align="right" src="http://rickgaribay.net/Images/customcontent/c1f79a9417a5_B3EF/image_3.png" width="244" height="110" /></a>With the release of .NET 4.5 Beta 1, all of the above have been updated to RFC 6455, which is the latest specification and expected to be final. </p> <p>Along with broad native support for WebSockets in modern browsers like Chrome, IE 10, Safari and FireFox, the standardization dust has settled making this the right time to jump in.</p> <p>In my talk, we took a lap around the WebSocket support in .NET 4.5, highlighting the APIs that Microsoft has made available in the Microsoft.WebSocket namespace that ships <a href="http://nuget.org/packages/Microsoft.WebSockets" target="_blank">as a package on NuGet</a>. While you can go as deep as you want in the new System.Net.WebSockets namespace that forms the core of Microsoft’s investment in the protocol, the Microsoft.WebSocket package provides higher level abstractions for developing WebSocket solutions today with WCF using WebSocketService and ASP.NET using WebSocketHandler.</p> <p>Since .NET 4.5 and Window 8/Server 8 have not yet been released, it is currently not possible to deploy your .NET 4.5 applications to Windows Azure. That said, while Windows Azure will certainly be updated to support these key technologies following RTM, Azure supports a variety of non-Microsoft programming languages and platforms including Node.js. </p> <p>Demonstrating the latest <a href="https://www.windowsazure.com/nodejs" target="_blank">Azure SDK for Node.js</a>, we got a fully RFC 6455 complain WebSocket service up and running on Windows Azure in a worker role running Node.js and using the WebSocket.IO module to integrate with Twitter’s Streaming API which provides a one-way firehose for tapping into Twitter’s event stream which proved to be a great example of using these capabilities together while having a little fun with HTML 5 JQuery and CSS 3.</p> <div align="center"> <table border="1" cellspacing="0" cellpadding="2" width="1366"><tbody> <tr> <td valign="top" width="81"> <p align="center"><strong>Demo</strong></p> </td> <td valign="top" width="562"> <p align="center"><strong>Summary</strong></p> </td> <td valign="top" width="472"> <p align="center"><strong>Artifacts</strong></p> </td> <td valign="top" width="249"> </td> </tr> <tr> <td valign="top" width="81">Demo 1</td> <td valign="top" width="562"> <p align="left">Live chat sample of Silverlight-based client and WCF Service running on Windows Azure. <br /> <br />Please note that this implementation is deprecated and will not be carried forward. <br /> <br />Instead, please use .NET 4.5 WebSocket support in WCF and ASP.NET. <br /></p> </td> <td valign="top" width="472"> <p align="left"> </p> <p align="left"> </p> <p align="left"> </p> <p align="left"><a title="http://html5labs.cloudapp.net/WebSockets/ChatDemo/wsdemo.html" href="http://html5labs.cloudapp.net/WebSockets/ChatDemo/wsdemo.html">http://html5labs.cloudapp.net/WebSockets/ChatDemo/wsdemo.html</a></p> </td> <td valign="top" width="249"> <p align="left"><a href="http://html5labs.cloudapp.net/WebSockets/ChatDemo/wsdemo.html"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://rickgaribay.net/Images/customcontent/c1f79a9417a5_B3EF/image_4.png" width="244" height="203" /></a></p> </td> </tr> <tr> <td valign="top" width="81"> <p align="left">Demo 2</p> </td> <td valign="top" width="562"> <p align="left">Simple “Hello World” example of ASP.NET ASHX handler using WebSocketHandler and HTML 5 client demonstrating a trivial “echo” service that displays the date/time each second. <br /> <br />Also included in the Demo 2 folder is a WCF version of the same implementation (which I did not demo during my talk). <br /></p> </td> <td valign="top" width="472"> <p align="center"> </p> <p align="center"><a title="http://sdrv.ms/HofK53" href="http://sdrv.ms/HofK53">http://sdrv.ms/HofK53</a> </p> <p align="center"> <br />Projects: <br />SimpleEventingSample <br />SimpleEventingService <br /> <br />Requires Visual Studio 11 Beta 1 &amp; Windows 8/Windows 8 Server</p> </td> <td valign="top" width="249"> <p align="left"><a href="http://rickgaribay.net/Images/customcontent/c1f79a9417a5_B3EF/image_5.png"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://rickgaribay.net/Images/customcontent/c1f79a9417a5_B3EF/image_thumb_3.png" width="244" height="190" /></a></p> </td> </tr> <tr> <td valign="top" width="81"> <p align="left">Demo 3</p> </td> <td valign="top" width="562"> <p align="left">Example of using the Twitter Search API as an event stream with WCF using  WebSocketService, Linq to Twitter and HTML 5 with some nice JQuery and CSS animation. <br /></p> </td> <td valign="top" width="472"> <p align="center"><a title="http://sdrv.ms/HofK53" href="http://sdrv.ms/HofK53">http://sdrv.ms/HofK53</a> <br /> <br />Projects: <br />StatusStreamClient <br />StatusStreamService <br />StatusStreamServiceTests <br /> <br /></p> <p align="center">Requires Visual Studio 11 Beta 1 &amp; Windows 8/Windows 8 Server</p> </td> <td valign="top" width="249"> <p align="left"><a href="http://rickgaribay.net/Images/customcontent/c1f79a9417a5_B3EF/image_6.png"><img style="border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://rickgaribay.net/Images/customcontent/c1f79a9417a5_B3EF/image_thumb_4.png" width="244" height="113" /></a></p> </td> </tr> <tr> <td valign="top" width="81"> <p align="left">Demo 4</p> </td> <td valign="top" width="562"> <p align="left">Another event streaming example, this time using the Twitter Streaming API, Node.js and WebSocket.IO in Windows Azure and HTML 5 animations with CSS 3 box shadow and rotate. <br /> <br />As opposed to the Twitter Search API used in Demo 3, you can see that events are immediately captured and the Streaming API is much more reliable than the Search API. <br /></p> </td> <td valign="top" width="472"> <p align="center"> </p> <p align="center"> </p> <p align="center"><a title="http://sdrv.ms/H1DVru" href="http://sdrv.ms/H1DVru">http://sdrv.ms/H1DVru</a></p> <p align="center"> <br />Use any text editor or your favorite JavaScript IDE. <br /></p> </td> <td valign="top" width="249"> <p align="left"><a href="http://rickgaribay.net/Images/customcontent/c1f79a9417a5_B3EF/image_7.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://rickgaribay.net/Images/customcontent/c1f79a9417a5_B3EF/image_thumb_5.png" width="244" height="183" /></a></p> </td> </tr> <tr> <td valign="top" width="81"> <p align="left">Deck</p> </td> <td valign="top" width="562"> <p align="left"></p> </td> <td valign="top" width="472"><a title="http://sdrv.ms/Hf5oZB" href="http://sdrv.ms/Hf5oZB"> <br /> <br /> <br />http://sdrv.ms/Hf5oZB</a></td> <td valign="top" width="249"><iframe style="padding-bottom: 0px; background-color: #fcfcfc; padding-left: 0px; width: 204px; padding-right: 0px; height: 118px; padding-top: 0px" title="Preview" height="120" marginheight="0" src="https://skydrive.live.com/embed?cid=DF930EE6F91132FD&amp;resid=DF930EE6F91132FD%21751&amp;authkey=ALQ9gS4_Yvb89c0" frameborder="0" width="98" marginwidth="0" scrolling="no"></iframe></td> </tr> </tbody></table> </div> <div align="center"> </div> <p>Please feel free to play with any of the samples, extend them and make them your own.</p> <p>Please remember that demos 2 and 3 require .NET 4.5 Consumer Preview and either Windows 8 or <a href="http://rickgaribay.net/Images/customcontent/c1f79a9417a5_B3EF/image_8.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" align="right" src="http://rickgaribay.net/Images/customcontent/c1f79a9417a5_B3EF/image_thumb_6.png" width="644" height="356" /></a>Windows 8 server.</p> <p>Since the Microsoft.WebSockets NuGet package is the easiest way to get started with WebSocketHandler and WebSocketService, I’d recommend starting with Demo 2 and Demo 3. </p> <p>For demo 4, you will need an Azure account which you can sign up for free (really, free) at <a href="http://azure.com">http://azure.com</a> </p> <p>As we discussed during my talk, even though .NET 4.5 and Windows 8 are not yet RTM:</p> <p>•Now is the time to dive into WebSockets in .NET 4.5!</p> <p>•Consider how WebSockets can improve existing near real-time messaging scenarios.</p> <p>•Start building WebSocket apps on Windows 8 and Windows Server 8 today.</p> <p>•.NET 4.5 support in Windows Azure is coming soon. In the meantime, consider alternate frameworks like Node.js which is supported today!</p> <p>Last but not least, here are the resources I provided on my last slide for easy access:</p> <p>•Microsoft.Web.WebSockets NuGet Package: <a href="http://nuget.org/packages/Microsoft.WebSockets">http://nuget.org/packages/Microsoft.WebSockets</a></p> <p>•Paul Batum’s blog: <a href="http://www.paulbatum.com/2011/09/getting-started-with-websockets-in.html">http://www.paulbatum.com/2011/09/getting-started-with-websockets-in.html</a></p> <p>•Damir Dobric’s blog on WCF WebSockets: <a href="http://developers.de/blogs/damir_dobric/archive/2011/11/26/wcf-duplex-via-websocket.aspx">http://developers.de/blogs/damir_dobric/archive/2011/11/26/wcf-duplex-via-websocket.aspx</a></p> <p>•ASP.NET Documentation: </p> <p>●<a href="http://msdn.microsoft.com/en-us/library/system.web.websockets(v=vs.110).aspx">http://msdn.microsoft.com/en-us/library/system.web.websockets%28v=vs.110%29.aspx</a></p> <p>●<a href="http://msdn.microsoft.com/en-us/library/system.net.websockets(v=vs.110).aspx">http://msdn.microsoft.com/en-us/library/system.net.websockets%28v=vs.110%29.aspx</a></p> <p>•WebSocket.IO: <a href="https://github.com/learnboost/websocket.io">https://github.com/learnboost/websocket.io</a></p> <p>•Nice CSS &amp; JQuery scripts/samples: <a href="http://marcofolio.net">http://marcofolio.net</a></p> <p>Last but not least, I’d like to thank <a href="http://twitter.com/paulbatum" target="_blank">@paulbatum</a>, PM at Microsoft working on the WCF and ASP.NET  WebSocket features for helping me grok WebSockets in .NET 4.5. His guidance and thought leadership around WebSocket are invaluable to the community, so if you run into Paul, thank him or better yet, buy him a beer.</p> <p>Happy Messaging!</p><img src="http://rickgaribay.net/aggbug/337.aspx" width="1" height="1" /> Rick G. Garibay http://rickgaribay.net/archive/2012/03/29/building-speedy-azure-applications-with-html5-and-web-sockets-today.aspx Thu, 29 Mar 2012 07:15:00 GMT http://rickgaribay.net/archive/2012/03/29/building-speedy-azure-applications-with-html5-and-web-sockets-today.aspx#feedback http://rickgaribay.net/comments/commentRss/337.aspx http://rickgaribay.net/services/trackbacks/337.aspx Node is Not Single Threaded http://rickgaribay.net/archive/2012/01/28/node-is-not-single-threaded.aspx <p>I recently got bitten by the Node.js bug. Hard. </p> <p>If you are even remotely technically inclined, it is virtually impossible to not be seduced by the elegance, speed and low barrier to entry of getting started with Node.js. After all, its just another JavaScript API, only this time designed for running programs on the server. This in and of itself, is intriguing, but there has to be more, much more, to compel legions of open source developers to write entire libraries for Node almost over night, not to mention industry giants like <a href="http://venturebeat.com/2012/01/24/why-walmart-is-using-node-js/" target="_blank">Wal-Mart</a> and <a href="http://www.windowsazure.com/en-us/develop/nodejs/" target="_blank">Microsoft</a> embracing this very new, fledgling technology that has yet to be proven over any significant period of time.</p> <p>As intriguing as Node is, I have a hard time accepting things at face value that I don't fully understand. When I don’t understand something, I get very frustrated. This frustration usually motivates me to relentlessly attack the subject with varying degrees of success (and sometimes even more frustration!).</p> <p>As such, this post is an attempt to collect my findings on how Node, and it’s alleged single-threaded approach to event-driven programming is different from what I know today. This is not a dissertation on event vs. thread-based concurrency or a detailed comparison of managed frameworks and Node.js. Instead, this is a naive attempt to capture my piecemeal understanding of <strong>how</strong> Node is different into a single post in hopes that comments and feedback will increase its accuracy in serving as a reference that helps to put in perspective for .NET developers how Node is different and what the hubbub is really all about.</p> <p>To that end, I <strong><em>sincerely would appreciate</em></strong> your comments and feedback to enrich the quality of this post as I found resources on the web that tackle this specific topic <a href="http://www.quora.com/In-Node-js-how-does-the-event-loop-work" target="_blank">severely lacking</a> (or I am just too dense to figure it all out).</p> <p>I’m going to skip the hello world code samples, or showing you how easy it is to spin up an HTTP or TCP server capable of handling a ridiculous amount of concurrent requests on a laptop because this is all well documented elsewhere. If you haven’t ever looked at Node before, check out the following resources which will help to kick-start your node.js addiction (the first hit is free):</p> <ul> <li><a href="http://www.youtube.com/watch?v=jo_B4LTHi3I" target="_blank">SF PHP User’s Group talk by Ryan Dahl</a> </li> <li><a href="http://nodebeginner.org/" target="_blank">Node Beginner Book by Manuel Kiessling</a> </li> <li><a href="http://www.youtube.com/watch?v=M-sc73Y-zQA" target="_blank">Cinco de Node talk by Ryan Dahl</a> </li> </ul> <p>Aside from the syntactic sugar that is immediately familiar to legions of web developers regardless of platform or language religion, you can’t come across any literature or talk on Node.js without a mention of the fact that what makes it all so wonderful is the fact that it is <strong>event-driven and <strong>single-threaded</strong>.</strong></p> <p>It is evident to me that there are either a lot of people that are much smarter than me and just instantly get that statement, as well as people that blindly accept it. Then there are those who haven’t slept well for the last week trying to figure out what the hell that means and how it’s different.</p> <p><strong><font size="3">Event-driven. So what? </font></strong></p> <p>I’ve written lots of asynchronous code and designed many messaging solutions on event-driven architectures. As a Microsoft guy, I’m pretty familiar with writing imperative code using Begin/End, AsyncCallbacks, WaitHandles,  IHttpAyncHandlers, etc. I’ve opted for ever permutation of WCF instancing and concurrency depending on the scenario at hand, and written some pretty slick WF 4 workflows that parallelize activities (yes, I know, its not really truly parallel, but in most cases, close enough). My point is, I get async and eventing, so what’s the big deal and how is Node any different than this, or the <a href="http://www.wischik.com/lu/AsyncSilverlight/AsyncSamples.html" target="_blank">nice new async language features coming in C# 5</a>?</p> <p><strong><font size="3">IIS and .NET as a Learning Model</font></strong></p> <p>When learning something new, it is a tremendous advantage to know nothing about the topic and start fresh. Absent of that, it is usually helpful to have a familiar model that you can reference that helps you to compare and contrast a new concept, progressively iterating to understand the similarities and differences. As a career-long enterprise guy, working almost exclusively on the Microsoft platform, my model is IIS/WAS and .NET., so let’s summarize how a modern web server like IIS 7+ works which will provide the necessary infrastructure to help frame how .NET’s (or Java) execution model works.<a href="http://learn.iis.net/file.axd?i=15"><img style="display: inline; float: right" border="0" alt="" align="right" src="http://learn.iis.net/file.axd?i=15" width="469" height="419" /></a></p> <p>As described on <a href="http://learn.iis.net/page.aspx/101/introduction-to-iis-architecture/" target="_blank">Learn.IIS.net</a>, the following list describes the request-processing flow that is shown to your right: </p> <ol> <li>When a client browser initiates an HTTP request for a resource on the Web server, HTTP.sys intercepts the request. </li> <li>HTTP.sys contacts WAS to obtain information from the configuration store. </li> <li>WAS requests configuration information from the configuration store, applicationHost.config. </li> <li>The WWW Service receives configuration information, such as application pool and site configuration. </li> <li>The WWW Service uses the configuration information to configure HTTP.sys. </li> <li>WAS starts a worker process for the application pool to which the request was made. </li> <li>The worker process processes the request and returns a response to HTTP.sys. </li> <li>The client receives a response. </li> </ol> <p>Step 7 is where your application (which might be an ASP.NET MVC app, a WCF or WF service) comes in. When WAS starts a worker process (w3wp.exe) the worker process allocates a thread for loading and executing your application. This is analogous to starting a program and inspecting the process in Windows Task Manager. If you open 3 instances of the program, you will see 3 processes in task manager and each process will have a minimum of one thread. If an unhandled exception occurs in the program, the entire process is torn down, but it doesn’t affect other processes because they are isolated for each other. </p> <p>Processes, however, are not free. Starting and maintaining a process requires CPU time and memory, both of which are finite, and more processes and threads require more resources. </p> <p>.NET improves resource consumption and adds an additional degree of isolation through Application Domains or AppDomains. AppDomains live within a process and your application runs inside an AppDomain.</p> <p>K. Scott Allen <a href="http://odetocode.com/Articles/305.aspx" target="_blank">summarizes</a> the relationship between the worker process and AppDomains quite nicely:</p> <blockquote> <p>You’ve created two ASP.NET applications on the same server, and have not done any special configuration. What is happening? </p> <p>A single ASP.NET worker process will host both of the ASP.NET applications. On Windows XP and Windows 2000 this process is named aspnet_wp.exe, and the process runs under the security context of the local ASPNET account. On Windows 2003 the worker process has the name w3wp.exe and runs under the NETWORK SERVICE account by default. </p> <p>An object lives in one AppDomain. Each ASP.NET application will have it’s own set of global variables: Cache, Application, and Session objects are not shared. Even though the code for both of the applications resides inside the same process, the unit of isolation is the .NET AppDomain. If there are classes with shared or static members, and those classes exist in both applications, each AppDomain will have it’s own copy of the static fields – the data is not shared. The code and data for each application is safely isolated and inside of a boundary provided by the AppDomain </p> <p>In order to communicate or pass objects between AppDomains, you’ll need to look at techniques in .NET for communication across boundaries, such as .NET remoting or web services. </p> </blockquote> <p>Here is a logical view borrowed from  <a href="http://www.matlus.com/instantiating-business-layers-asp-net-performance/" target="_blank">a post by Shiv Kumar</a> that helps to show this relationship visually:</p> <p><img title="IISAppPoolAndGlobal" border="0" alt="IISAppPoolAndGlobal" src="http://www.matlus.com/content/uploads/2011/01/IISAppPoolAndGlobal_7a87db2b-b0be-4e84-96dd-d2bf6d0f4cfa.jpg" width="367" height="271" /></p> <p>As outlined in steps 1 – 7 above, when a request comes in, IIS uses an I/O thread to dispatch the request off to ASP.NET. ASP.NET immediately sends the request to the CLR thread pool which returns immediately with a pending status. This frees the IIS I/O thread to handle the next request and so on. Now, if there is a thread available in the thread pool, life is good, and the work item is executed, returning back to the I/O thread in step 7. However, if all of the threads in the thread pool are busy, the request will queue until a CLR thread pool thread is available to process the work item, and if the queue length is too high, users will receive a somewhat terse request to go away and come back later.</p> <p>This is a bit of an extreme trivialization of what happens. There are a number of knobs that can be set in IIS and ASP.NET that allow you to tune the number of concurrent requests, threads and connections that affect both IIS and the CLR thread pool. For example, the IIS thread pool has a maximum thread count of 256. ASP.NET initializes its thread pool to 100 threads per processor/core. You can adjust things like the maximum number of concurrent requests per CPU (which defaults to 5000) and maximum number of connections of 12 per CPU but this can be increased. This stuff is not easy to grasp, and system administrators dedicate entire careers to getting this right. In fact, it is so hard, that we are slowly moving away from having to manage this ourselves and just paying some really smart engineers to do it for us, at massive scale. </p> <p>That said, if you are curious or want to read more, <a href="http:// http://blogs.msdn.com/b/tmarq/archive/2007/07/21/asp-net-thread-usage-on-iis-7-0-and-6-0.aspx" target="_blank">Thomas Marquardt</a> and <a href="http://msdn.microsoft.com/en-us/magazine/cc164128.aspx" target="_blank">Fritz Onion</a> cover IIS and CLR threading superbly in their respective posts. </p> <p>Back to the example. If all of your code in step 7 (your app) is synchronous, then the number of concurrently executing <strong>requests</strong> is equal to the number of <strong>threads</strong> available to concurrently execute your requests and if you exceed this, your application/service will simply grind to a halt. </p> <p>This is why asynchronous programming is so important. If your application/service (that runs in step 7) is well designed, and makes efficient use of IO by leveraging async so that work is distributed across multiple threads, then there are naturally more threads always ready to do work because the the total processing time of a request becomes that of the longest running operation instead of the sum of all operations. Do this right, and your app can scale pretty darn well as long as there are threads available to do the work. </p> <p>However, as I mentioned, these threads are not free and in addition, there is a cost in switching from the kernel thread to the IIS thread and the CLR thread which results in additional CPU cycles, memory and, latency. </p> <p>It is evident that to minimize latency, you apps must perform the work they need to as quickly as possible to keep threads free and ready to do more work. Leveraging asynchrony is key. </p> <p>Even in era where scaling horizontally is simply a matter of pushing a button and swiping a credit card, an app that scales poorly on premise will scale poorly in the cloud, and both are expensive. Moreover, having written a lot of code, and worked with and mentored many teams in my career, I’ll admit that writing asynchronous code is just plain hard. I’ll even risk my nerd points in admitting that given the choice, I’ll write synchronous code all day long if I can get away with it.</p> <p><font color="#000000" size="3"><strong>So, what’s so different about Node?</strong></font></p> <p>My biggest source of confusion in digging into Node is the assertion that it is event-based <strong><em>and</em></strong> single threaded. </p> <p>As we’ve just covered in our learning model, IIS and .NET are quite capable of async, but it certainly can’t do that on a single thread. </p> <p>Well, guess what? Neither can Node. Wait, there’s more. </p> <p>If you think about it for just a few seconds, highly concurrent, event-driven and single threaded do not mix. Intentional or otherwise, “single threaded” is a red herring and something that has simply been propagated over and over. Like a game of telephone, it’s meaning has been distorted and this is the main thing that was driving me NUTS.</p> <p>Let’s take a closer look. </p> <p>In Node, an program/application is created in a process, just like in the .NET world. If you run Node on Windows, you can see an instance of the process for each .js program you have running in Task Manager. </p> <p>What makes Node unique is *not* that it is single-threaded, it’s the way in which it manages event-driven/async for you and this where the concept of an Event Loop comes in.</p> <p>To provide an example, to open a WebSocket server that is compliant with the latest IETF and W3C standards, you write code like this written by my friend <a href="http://twitter.com/adammokan" target="_blank">Adam Mokan</a>:</p> <pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 1: <span style="color: #0000ff">var</span> ws = require('websocket.io') </pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 2: , server = ws.listen(3000) </pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 3: </pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 4: server.on('connection', <span style="color: #0000ff">function</span> (socket) { </pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 5: </pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 6: console.log('connected to client'); </pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 7: socket.send('You connected to a web socket!'); </pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 8: </pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 9: socket.on('message', <span style="color: #0000ff">function</span> (data) { </pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 10: console.log('nessage received:', data); </pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 11: }); </pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 12: </pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 13: socket.on('<span style="color: #0000ff">close</span>', <span style="color: #0000ff">function</span> () { </pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 14: console.log('socket <span style="color: #0000ff">closed</span>!'); </pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 15: }); </pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> 16: });</pre></pre> <p> </p> <p>As soon as ws.listen(3000) executes, a WebSocket server is created on a <strong>single thread</strong> which listens continuously on port 3000. When an HTML5 WebSocket compliant client connects to it, it fires the ‘connection’ event which the loop picks up and immediately publishes to the thread pool (see, I told you it was only half the story), and is ready to receive the next request. Thanks to the V8 Engine, this happens really, really fast. </p> <p>What’s cool is that the program *is* the server. It doesn’t require a server like IIS or Apache to delegate requests to it. Node is fully capable of hosting an HTTP or TCP socket, and it <em><strong>does do this on a single thread. </strong></em>On the surface, this is actually quite similar to WCF which can be hosted in any CLR process or IIS, and to take this analogy one step further, you could configure a self-hosted WCF service as a singleton with multiple concurrency for a similar effect. But, as you well know, there is a ton of work that now needs to be done from a synchronization perspective and if you don’t use async to carry out the work, your performance will pretty much suck.</p> <p>Wait! You say. Other than an (arguably) easier async programming model, how is this different than IIS/WAS and ASP.NET or WCF? Take a look at this drawing from from a great <a href="http://www.aaronstannard.com/post/2011/12/14/Intro-to-NodeJS-for-NET-Developers.aspx" target="_blank">post</a> by <a href="http://www.aaronstannard.com/post/2011/12/14/Intro-to-NodeJS-for-NET-Developers.aspx" target="_blank">Aarron Stannard</a> who just happens to be a Developer Evangelist at Microsoft:</p> <p><img title="nodejs for dotnet" border="0" alt="nodejs for dotnet" src="http://www.aaronstannard.com/image.axd?picture=nodejs%20for%20dotnet_thumb.png" width="557" height="352" /></p> <p>As you can see, there is more than one thread involved. I don’t mean this to sound like a revelation, but it is a necessary refinement to explain how the concurrency is accomplished. But, and it’s a BIG but, unlike .NET, you don’t have a choice but to write your code asynchronously. As you can see in the code sample above, you simply can’t write synchronous code in Node. The work for each event is delegated work to an event handler by the loop immediately after the event fires . The work is picked up by a worker thread in the thread pool and then calls back to the event loop which send the request on its way. It is kind of subtle, but the single thread is *almost* never busy and when it is, it is only busy for a very short period of time. </p> <p>This is different from our model in at least 3 ways I can think of:</p> <ol> <li>Your code is aysnc by default, period. </li> <li>There is no context switching as the Event Loop simply publishes and subscribes to the thread pool. </li> <li>The Event Loop never blocks. </li> </ol> <p><strong>Your code is aysnc by default, period. </strong></p> <p>This can’t be understated. Writing asynchronous code is hard, and given the option, most of us won’t. In a thread-based approach, particularly where all work isn’t guaranteed to be asynchronous, latency can become a problem. This isn’t optional in Node, so you either learn async or go away. Since it’s JavaScript, the language is pretty familiar to a very, very wide range of developers.</p> <p>Node is very low level, but modules and frameworks like Express add sugar on top of it that help take some of the sting out of it and modules like Socket.IO and WebSocket.IO are pure awesome sauce.  </p> <p><strong>There is no context switching as the Event Loop simply publishes and subscribes to the thread pool</strong></p> <p>I am not a threading expert, but simple physics tells me that that 0 thread hops is better than a minimum of 3. </p> <p>I guess this might be analogous to a hypothetical example where HTTP.sys is the only gate, and WWW Publishing Service, WAS, ASP.NET are no longer in play, but unless HTTP.sys was changed from a threaded approach for concurrency to an Event Loop, I’m guessing it wouldn’t necessarily be apples to apples.</p> <p>With Node, while there are worker threads involved, since they are each carrying out one and only one task at a time asynchronously, the CPU and memory footprint should be lower than a multi-treaded scenario, since less threads are required. This tends to be better for scalability in a highly concurrent environment, even on commodity hardware.</p> <p><strong>The Event Loop never blocks. </strong></p> <p>This is still something I’m trying to get my head around, but conceptually, what appears to be fundamentally different is that the Event Loop always runs on the same, single I/O thread. It is never blocking, but instead waits for something to happen (a connection, request, message, etc.) before doing anything, and then, like a good manager, simply delegates the work to an army of workers who report back when the work is done. In other words, the worker threads do all the work, while the Event Loop just kind of chills waiting for the next request and while it is waiting, it consumes 0 resources. </p> <p>One of the things that I am not clear on is that when the callbacks are serialized back to the loop, only one callback can be handled at one time, so, if a request comes in at the exact same time that the loop is temporarily busy with the callback, will that request block, even if just for the slightest instant? </p> <p><strong><font size="3">So?</font></strong></p> <p>Obviously, still being very new to Node, I have a ton to learn, but it is clear that for highly concurrent, real-time scenarios, Node has a lot of promise. </p> <p>Does this mean that I’m abandoning .NET for Node? Of course not. For one, it will take a few years to see how things pan out in the wild, but the traction that Node is getting can’t be ignored, and it could very well signal the shift to event-based server programming and EDA in the large.</p> <p>I’d love to know what you think, and as I mentioned in the introduction, welcome your comments and feedback.<!--EndFragment--></p> <p><strong>Resources:</strong></p> <ul> <li><a href="http://www.matlus.com/instantiating-business-layers-asp-net-performance/">http://www.matlus.com/instantiating-business-layers-asp-net-performance/</a></li> <li><a href="http://odetocode.com/Articles/305.aspx">http://odetocode.com/Articles/305.aspx</a></li> <li><a href="http://learn.iis.net/page.aspx/101/introduction-to-iis-architecture/">http://learn.iis.net/page.aspx/101/introduction-to-iis-architecture/</a></li> <li><a href="http://msdn.microsoft.com/en-us/magazine/cc164128.aspx">http://msdn.microsoft.com/en-us/magazine/cc164128.aspx</a></li> <li><a href="http://blogs.msdn.com/b/tmarq/archive/2007/07/21/asp-net-thread-usage-on-iis-7-0-and-6-0.aspx">http://blogs.msdn.com/b/tmarq/archive/2007/07/21/asp-net-thread-usage-on-iis-7-0-and-6-0.aspx</a></li> <li><a href="http://blogs.msdn.com/b/tmarq/archive/2010/04/14/performing-asynchronous-work-or-tasks-in-asp-net-applications.aspx">http://blogs.msdn.com/b/tmarq/archive/2010/04/14/performing-asynchronous-work-or-tasks-in-asp-net-applications.aspx</a></li> <li><a href="http://nodebeginner.org/">http://nodebeginner.org/</a></li> <li><a href="http://www.beakkon.com/geek/node.js/why-node.js-single-thread-event-loop-javascript">http://www.beakkon.com/geek/node.js/why-node.js-single-thread-event-loop-javascript</a></li> <li><a href="http://www.aaronstannard.com/post/2011/12/14/Intro-to-NodeJS-for-NET-Developers.aspx">http://www.aaronstannard.com/post/2011/12/14/Intro-to-NodeJS-for-NET-Developers.aspx</a></li> <li><a href="http://www.quora.com/How-does-an-event-loop-work">http://www.quora.com/How-does-an-event-loop-work</a></li> <li><a href="http://debuggable.com/posts/understanding-node-js:4bd98440-45e4-4a9a-8ef7-0f7ecbdd56cb">http://debuggable.com/posts/understanding-node-js:4bd98440-45e4-4a9a-8ef7-0f7ecbdd56cb</a></li> </ul><img src="http://rickgaribay.net/aggbug/327.aspx" width="1" height="1" /> Rick G. Garibay http://rickgaribay.net/archive/2012/01/28/node-is-not-single-threaded.aspx Sun, 29 Jan 2012 06:17:00 GMT http://rickgaribay.net/archive/2012/01/28/node-is-not-single-threaded.aspx#feedback 4 http://rickgaribay.net/comments/commentRss/327.aspx http://rickgaribay.net/services/trackbacks/327.aspx