0

Concurrency On Windows

It seems that no matter where I go or who I talk to that multithreading, concurrency, parallelism, synchronization and asynchronous programming are just hard topics for people to understand.  In general, here are my general simple guidelines that I recommend people to follow.

Taking a Lock

Think of taking a lock?  Think again.  Think about it some more.  Think another time.  Then go ask someone you know who understands locking and synchronization.  You may find a way to structure your code so that it does not have to take a lock.

Parallelism vs. Asynchronous

I am all for taking advantage of hardware especially CPUs using parallelism.  Keep in mind that there are different types of parallelism such as IO vs. CPU parallelism.  Don’t get them confused.  Also, know what frameworks you are using for parallelism.  Some are designed for CPU parallelism which means that if you need IO parallelism, you might do better with not using these frameworks.

There are many times that people think that they need parallelism, but in reality they may just need asynchronous operations.  This is especially true if you are doing file operations, web service calls or database calls.  This usually arises from the need to not block, especially in the case of user interface interactions.

More Threads Is Not Better

Do not think that more threads is better.  In fact, in almost all cases more threads is absolutely bad.  A single CPU can only execute one thread at a time.  To achieve multitasking a CPU must switch between threads.  This switching between threads is known as context switching.  The more context switching the less time is spent actually executing your code.  In general, assuming that you have a N core system, the most efficient number of threads will be N.

Book Recommendations

Without a doubt the following books are some of the best books on parallelism, concurrency and multithreading for Windows.  I highly recommend any of these books.

Concurrency Programming on Windows

Parallel Programming with Microsoft .NET: Design Patterns for Decomposition and Coordination on Multicore Architectures

Threading in C# (Free E-Book)

0

TIP #1 – Position XAML Attributes On Separate Lines

image

During development of a WPF or Silverlight application one will come across the need to compare XAML changes with what resides in source control.  At this point one may need to merge the files.  If you have ever worked with XML you will know that XML merging can be frustrating.  XAML is a XML-based format so your experience with merging will depend on your source control system and its merging capabilities for XML.  If your source control system doesn’t have great XML merging then you may need to help it along.  One way to do this is by positioning each attribute on a separate line.  To change this setting go to Tools –> Options –> Text Editor –> XAML –> Formatting –> Spacing to change the Attribute Spacing.  This will help a merging tool do line compares instead of XML differencing.

0

Notifications and Events – The Problem

thumbnail

This week I was presented with a notifications and events problem.  The basic problem is this.  When something changes in the database by one user we need to notify other users that this change occurred.  These change notifications should survive application lifetime.  That means that the next time the user logs in they should be notified of any changes that occurred when the application was down.  The notifications should also arrive in near real-time to alert users that something has changed.

In the past, there have been many ways to solve this issue on the Microsoft platform.  Lately though many of the options are scattered to the winds.  One of the more popular ways years ago was SQL Notification Services.  That feature of SQL Server was deprecated.  Actually it was terminated with extreme prejudice since it was completely removed from SQL Server.

So what options does one have on the Microsoft platform?  In short, not many.  It is a shame too.  Of course one could get a third party product or look to an open source project that might handle this.  The challenge is that this complicates the architecture, design, and overall implementation.  Think about it.  You have an entire application whose main function is NOT notifications or events, but yet you need this one feature.  So let us discuss some of the available options we have today.

Option #1 – Service Bus

Dare I say this word, “Service Bus”.  Many of the features that we need like communication back to a client, notifications and events, durability, reliability, and more can be found in a service bus.  Unfortunately just because it walks like a duck, quacks like a duck, does not mean it is a service bus.

A service bus is the sledgehammer approach.  It can facilitate many of our needs, but do we need the deployment, infrastructure, and overhead of a service bus for this one feature.

Also, if you have the need for durable notifications and events, you better ask the question “Are my notifications and events inherently tied to my application?”  If so, then this is not a service bus that you need.  There are plenty of reasons for this.  Service buses often help with integration problems.  This particular case is NOT an integration problem.  It is a problem inherently tied to a single application.  Another good reason is deployment and operations.  You need to backup your application right.  Well if you tie yourself to a service bus you may need to backup your application as well as the service bus to ensure consistency on restores.  You even complicate the deployment of your application.  I could go on, but these are two great examples of why not a service bus.

So the answer to a service bus is “No”.

Option #2 – WCF Callback Contracts (aka Duplex Services)

WCF callback contracts has so many challenges.  Things like in-memory state and connection issues, lack of durable notifications and events, load balancing concerns, and more.  This is a great feature to communicate from server to a client.  So when a notification does need to happen, it is easier to communicate to the client.  Unfortunately it does not solve durability, change detection, and application lifetime.  Therefore this cannot be used on its own.

Option #3 – Polling

Ugh!  When in doubt “Poll”?  Really, we have to use polling to determine if something has be updated.  Very frustrating to say the least.  I always like to consider polling as a last resort.  The challenge with polling is that it often consumes resources for no good reason.  A polling loop can spend more time doing nothing and very little time doing something useful.  Another big challenge is that there maybe latency of any notifications and events that need to be sent based on the polling interval.  Polling is an approach that cannot be used on its own.

Option #4 – SQL Query Notifications

SQL Query Notifications (SQN) like several of the other technologies discussed does not solve this issue on its own either.  SQN only notifies some process (usually a middle-tier) of changes to data in the database.  This is often used for updating caches in the middle-tier themselves.  It is a great way to detect when a change has occurred, but it does not handle communication from server to client.

Option #5 – Long Polling and SignalR

I am bringing up long polling and SignalR because someone else brought this up to me during our discussions.  This technology is great, but it is not the problem we are trying to solve.

SignalR is an HTTP-based client and server communication framework.  It is meant for sophisticated interactions between client and server using traditional web-based communication (i.e. HTTP).  What if our problem is not HTTP-based?  For that matter, what if our problem is not Internet-based and really confined to an enterprise network.  Then WCF callback contracts might be the better answer here.

Option #6 – netHttpBinding and WebSockets

Hmm…  YAB (i.e. Yet Another Binding)!  Well this WCF binding solves a few things.  When enabled it uses websockets for its communication from server to client.  This is much better than the duplex HTTP channels, ex. wsDualHttpBinding, previously used by many for duplex communication over HTTP with WCF.  At least with the netHttpBinding you can use websockets instead of opening up multiple connections to the server and polling.

Oops…  Did I speak to soon?  Why yes I did.  The netHttpBinding is only supported with Windows 8 clients.

Ok, enough for now!  We will continue this post in a few days.

0

First Week Down, Next Week Plan

Many things happened this week that were amazing.  Here is some reflection on some of them.

  • Time, Time, Time!  I am talking about time management.  Because of some of the changes I have made like commuting on the train I am now able to focus on work and home life.  Every day I wanted to be home for dinner I was.
  • Lots of opportunity to have a big impact.  What is always great is being given responsibility.  There is definitely no shortage of that at the moment.  In fact, I have to constantly remind myself about small successes … “inch pebbles”, “inch pebbles”. “inch pebbles”.
  • Boston, Boston, Boston!  I really like the city.  It is fun, fun, fun!  Now that my schedule has changed I am able to enjoy my surroundings.  This week we went to a number of places for lunch which were great.  That is good for the first week.  All next week [with the exception of one day] I plan to bring lunch.
  • Commuting on the train has opened up some opportunities.  For example, I can now take the train and subway anytime I want without extra cost.  This allows for extracurricular activities like going to the Boston Hadoop / Predictive Analytics Meetups.  In fact, next week is Chris Bowen’s talk on Windows 8.

Next week will be very interesting.  Here is what I am hoping to accomplish.

  • I would like to meet more people at my work.  More specifically, people from the other office.  I should have more than a few opportunities to do that next week.
  • Work out time!  I have been contemplating joining a gym for some time.  What has prevented it has been the lack of a consistent schedule and variability on my travels.  Now that my schedule is very consistent and my travels are consistent I have a plethora of options.

Option #1 – The Equinox

This is the gym at the bottom of the building where I work.  This is most likely the best option of all of them.  It is the closest gym and whether I take the train or drive there is no excuse for me to not work out.

image

Option #2 – Spa at the Boston Harbor Hotel

This is the fitness center at the Boston Harbor hotel.  What is great about this gym is the “no excuse” services they offer like providing workout clothes if you forget them.  They even have a pool.  The one drawback is that it is very expensive.

Option #3 – Anytime Fitness Groton, MA

This is a very nice and clean facility in my town.  While the facility is very nice, it is small and they don’t offer the same amenities as the other gyms I am considering.  They are also not that much different in price compared to some of the other gyms.

Option #4 – Sports Club / LA Boston

Sports Club / LA in Boston???   Why not call this Sports Club / Boston?  Anyways, this is probably the best gym ever.  It has almost everything with the exception of a pool.  Lots of amenities and services.  Definitely a people watching place too.  Supposedly The Rock works out here when he is in town.  Also, the Yankees and other teams that play the RedSox workout here too.  The drawback is that it is so expensive it isn’t even funny.

0

Day 6 – First Week Almost Done

Here we are on Day 6!  I wanted to bookmark some successes this week.

  • Figured out the train to and from Boston.  What a much better commute than I had before.  In fact, it is amazingly better.  I am disappointed in myself that I didn’t commute by train previously in my last job.  Still it is a much different job so I don’t think that would have helped previously.
  • Opportunity, Opportunity, Opportunity!  There is tons of opportunity at my new job to help.  That is very exciting.  Talked to one of the teams I am working with at my new job.  What a bunch of great people.  I am looking forward to working with them.
  • My new boss pointed me to a cool coffee company, Flat Black Coffee Company.  Looks like a great place to start out the day.
  • Moved our personal email and hosting from DiscountASP.NET to GoDaddy!  What a difference that makes.  More, more, more features for less price.

 

0

Day 3 – First Day of My New Job

Today was a great day.  I started off the day with my orientation followed by an easy day of setting up my computer, getting my phone setup, and other similar tasks.  I even got to sit in on a code review for an interview candidate.

What is really nice is that the new company I work for cares about time you spend at work and at home.  They made a point that I should go home at 5PM today.  I even noticed many of the people leaving at about 4:30PM to catch the train to go home.  That was kind of nice to see.  They even made a point of me not having a laptop so that I didn’t take work home.

Today was also interesting from a technology perspective.  I had conversations on many topics like HTML5, NOSQL (Raven, Mongo, Couch, Riak), Hadoop, SignalR, WPF, WCF, REST, ASP.NET WebAPI and much more.  Even if I don’t get to use any of these it is still great to be able to discuss these technologies and how they can be leveraged for the business.

I was going to go to HTML5 Boston this evening, but the topic was pretty basic and I figured it would be best to get home to see the wife and kids.  Mission accomplished!  I ate dinner with the wife and kids.

Tomorrow will be my first real commute on the train.  That should be interesting.

0

Day 2 – Preparation is Key

Today is all about preparation.

I started off this morning with my new ritual of trying to come up with new ideas, researching thoughts on other ideas, and doing some personal coding.  This morning is all about the ASP.NET WebAPI.  Being that I am an author of a book on WCF I wondered what my experience with the ASP.NET MVC4 WebAPI would be.  So far I feel like I am banging my head against the wall.  Mostly because of the lack of good samples on how to use it.  No matter, I will figure it out.  There are some good blog posts out there and I will save them for later reading.

“Daddy, I am not feeling well!”  … “Are you hungry?”  …  “I think so.”

Usually we are ahead of this, but my son wanted food real early this morning.  My daughter came downstairs partially dressed in her lacrosse uniform.  Fortunately breakfast was almost ready.  Waffles, bananas, and milk!  Nicki rolls downstairs, grabs a yogurt, and she and Charlotte went to her first lacrosse game.  Matthew and I stayed behind to focus on some things.

So preparation for today includes the following:

  • Double checking the train schedule for my first commute into Boston.
  • Making sure I have good clothes ready for my first day.
  • Ensuring Matthew and I get a hair cut.
  • Checking tomorrow’s Meetup events and determining if there is any I need to go to.
  • If so, then invite a few friend’s that just might be interested in going as well.
  • Making sure that I have everything for my orientation at 9AM tomorrow morning.

I also want to work on the front part of the garage.  We still have boxes from when we moved in 21 months ago.  More to follow!

0

First Day of My Entrepreneurial Life

Yesterday was my first full day on starting my entrepreneurial life.  It was a very good day.  It started with me working on some new ideas, researching some thoughts, and doing some personal coding which I haven’t done in a long while.  I then followed this with some personal branding efforts where I researched WordPress themes, plug-ins, and hosting.  I have to give a shout to Thomas LaRock for giving me suggestions on this over one year ago.  Thanks Thomas!

The kids awoke and started watching TV.  With Matthew being sick the last two weeks we were inclined to let them, but not for long.  Quickly we had an idea to go get breakfast at one of our favorite diners, the Pepperell Spa.  The diner is only a mile or two from our house.  During the summer we usually ride our bikes since we are not far from the Nashua River Rail Trail.  Today we did not ride our bikes even though the kids pleaded for us to do so.  The kids got French toast with fruit which is their favorite.  So that helped!

We followed our breakfast with some work in the yard.  The kids’ swing set was not anchored properly by the previous owners nor was the ground underneath it mulched properly.  So we spent the last few weekends digging, digging, and digging.  Today we dug some more, anchored the swing set, and put some rubberized mulch down.  I small success for us.  We think we still need to put in two more anchors and a couple more bags of mulch.

As a treat for working hard, we took the kids to the Pepperell Carnival in support of Pepperell’s 4th of July celebration.  It is a small little carnival.  Probably the smallest carnival a town could actually have.  That was good because it meant that we did not spend much money.  Some rides, food, arcade games later and we were satisfied with our success with this quick distraction.

Back to home, we settle in, have the kids get a shower, and come downstairs.  Nicki helped Charlotte with her whale project for school.  Nicki is awesome like that.  We then settled into a quiet evening with the family followed by the kids going off to bed.

All this was followed by me working a little more on some new ideas, researching some more thoughts, and doing some personal coding.  Topics of interest included SQL Server 2012, SQL Azure, and the new WebAPI in ASP.NET MVC4.

0

The Life of an Entrepreneur

I am embarking on a new future as an entrepreneur.  The plan is to not be an entrepreneur of a business or company, but of life.  Over my career I have worked very hard getting to where I am now.  It is time that I take the next big step in life where I focus on those things that I am most passionate about.

Over the years I have worked for some great companies including BlueMetal Architects, Microsoft, and many more.  During this time I have had the opportunity to work with many Financial Services companies and always enjoyed working with them.  I have the opportunity to work for a great company in downtown Boston.  Because of this I have decided to leave BlueMetal Architects.  This is an opportunity for me to work in an industry that I enjoy very much.  Thank you to my new employer for this great opportunity.  That also means that I must say farewell to BlueMetal Architects.  Thank you for an amazing journey.  I wish everyone at BlueMetal great success in their endeavors.

Next, I am going to work more on being a Husband and Father.  I like working hard and helping others.  This needs to come with balance so that one can continue to be productive both in work and in life.  That means taking on less and focusing on those things that matter most.  It also might mean that I give up some things that I do now and take on some things that I have neglected.  It could be as simple as yard work.

Entrepreneurs thrive through many, many small successes, dedication, and helping others.  This will require focus and organization to make sure that one takes time for even the small things.  The end result is hopefully amazing things that one could not accomplish alone, but with others.

0

HTML5 and JavaScript: The Plethora of Libraries and Frameworks

Today we are having an HTML5 overview, understanding what is available, and taking a look at some of the following HTML5 and JavaScript Libraries and Frameworks.  The positive thing is that your options are plentiful.  The options available range from opensource to commercial.  Sifting through which frameworks make sense for us is going to be a challenge, but fun.

  • modernizr
  • jQuery
  • Dojo
  • easelJs
  • html5shiv
  • knockOutJs
  • Kendo UI
  • Sencha/Ext JS
  • Initializr 2
  • HTML5 Boilerplate
  • Foundation
  • WinRT/WinJS
  • DHTMLX Touch

… and many others.