The concept of concurrency is not an easy concept to grasp, when dealing with concurrency - the main enemy when doing any task in parallel are shared resources. This is why functional programming as a concept has gotten a lot of attention due to it’s potential in this modern age where there is an abundant amount of CPU core’s, making it much more scalable for parallel computing.
What about the
Object Oriented Approach? well, we’ve been dealing with concurrency problems for quite some time, and in
.NET, we have the we have the
Task Parallel Library(TPL). TPL makes concurrency patterns easier to implement. Let’s have a look at one of the most common problems in concurrency - race conditions.
So, you have some type of application that does simple image manipulation - in most web applications case, resizing. You use some library, you construct an object with the image binary as a stream, and it does some wizardry magic and poof, you’ve just resized the image and stored it in a file in an image format of your choosing.
But wait - some image formats aren’t that trivial. Maybe we don’t care too much about the detail of how it does this, but we do care about what happens to our streams, how it’s used, and how much memory is consumed - after all, we wouldn’t want our application to crash or become unresponsive, right?
I’ve recently been heavily involved in moving towards a Service Oriented Architecture - and the most common form of Transport / Network Protocol used is of course,
HTTPdue to tooling and statelessness.
HttpClientis well known for being thread safe. Infact, it is very much encouraged to instantiate a
HttpClientobject and keep it in memory for as long as you need, this avoids the extra cost needed for reconstructing the object.
But, is it really that thread safe? Well, after some experiments with high volume of requests, it turns out - not completely / it depends.
The process of taking away or removing characteristics from something in order to reduce it to a set of essential characteristics
The idea behind abstraction is to hide complexity - we try to hide away all the complex details. For example, you may want to persist some type of data - that’s the high level view of what we want to be able to do. Whether we’re storing that in a text file, a database or what not, we shouldn’t really care, that’s someone else’s problem, that is an implementation detail - one less thing to worry about, all we know is that our data will be persisted somewhere. We don’t really care where or how.