Friday, October 10, 2014

Speaking on Lambda Jakarta: delivering intro to concurrency and asynchrony

Now it’s Lambda Jakarta meetup time! This meetup is on 4th October, 2014. Again, thanks to Traveloka for preparing the place for us to meet!

This time, Abdullah was presenting about the problem of concurrency titled: “Promise of Better Concurrency in Functional Programming: Big Win or BS?”. Yes, concurrency is everywhere now, and it’s becoming more and more relevant because of the fact that nowadays CPU is not getting speedier, but the CPU is keep getting denser with more core CPUs.

WP_20141004_004

Even on my laptop, the HP Envy beefed with intel CORE i7, it has 4 core and each core has 2 logical hyperthreading:

HPEnvy_TaskManager

This makes the logical overall CPU to be 8 logical CPUs! As we see, the clock speed is only at 2.39Ghz.

And this has becoming trend, not just from Intel. AMD has begun releasing microprocessor using this scheme/model.

Abdullah in his presentation was quoting this nice article from Herb Sutter (the Visual C++ lead dev of Microsoft) about “Free lunch is over.” published in 2005.

Herb_CPU_chart

He said that developer should not depend on CPU speed, instead they should begin to think on how to maximize the existing CPU cores. Otherwise the developed application will always run on one core and the rest of CPU core will be wasted. This of course will have negative impact not just on performance, but it will make the application to lose competitive factor of being efficient and support multi core.

Herb also added an undeniable fact of concurrency, it’s not just becoming relevant but it’s already relevant at the time of his writing!

The known concept of these maximizing cores to run at many cores, hence running multiple processes at a time is called parallel programming or on more abstract, parallelism.

This is the original link of the article: http://www.gotw.ca/publications/concurrency-ddj.htm

But concurrency doesn’t stop at just parallelism. Concurrency is also dealing with states, dealing with race conditions, and also traditional concept of operating system such as locks, semaphores, mutexes, and execution contexts.

Now execution contexts are becoming more relevant as the advances in hardware are allowing us to free us from having to wait for blocking operations such as I/O (including networks, printers). But then the software has to leverage this feature as much as possible by freeing current thread to be available for other execution context. The thread doesn’t have to be multithread, as you can still use the same thread but with different execution context.

This concept is known for asynchronous programming, or simply just asynchrony. Most programming languages handles this by providing state continuations such as “Futures” and “Promises”, or using complex callback with support for function as parameter (delegate in .NET, functional interface in Java 8, function in Haskell, Scala, and other functional programming languages).

I was also helping Abdullah to further explain asynchrony in the pragmatic perspective.

WP_20141004_016

The easiest way to explain asynchrony is if we are ordering food at a restaurant:

  1. We order the food/beverages and we are served by a waiter
  2. Waiter deliver the order list to the cook
  3. Waiter serves other customer without waiting the cook to complete our order
  4. Our order is complete, and the cook is telling the waiter by putting our finished order at the waiter tray (this is the callback)
  5. Waiter checks the tray, grabs the finished order, and delivers the order to us

I also promised the audience that the next meetup, I will deliver small presentation about asynchrony sample in detail Smile

The gory detail of concurrency is also nicely explained by this guy (formerly Oracle’s Java developer, now one of NodeJS founder) Bryan Cantrill in his excellent article: https://blogs.oracle.com/bmc/entry/concurrency_s_shysters

That’s all, folks!

This is the official landing page of this session’s Lambda Jakarta: http://www.meetup.com/Lambda-Jakarta/events/206904832/

If you live in nearby Jakarta, I encourage you to participate on this meetup, guys!

No comments:

Post a Comment