Code Monkey home page Code Monkey logo

concurrencyvsparallelsample's Introduction

This repo implements a concurrent AND parallel downloader in multiple languages. Currently, the languages it is programmed in is:

  • C#
  • Go (WIP)

This list is evolving!

Why?

Because Paralleism and Concurrency are two completely different issues, and I hope to demonstrate the difference through this simple example repo. Also, it's a good task to try building to test out new languages.

The specification

The task is a very simple Hacker News downloader. It is a command-line based launcher. On program start, it will make a connection to the Hacker News API and download the URLs of the top 20 websites. Then, it will download the HTML of those URLs, and perform a parallel split of the HTML by whitespace. After the word count is done, it is put into a queue, and printed out one by one to the console.

Sample output:

https://example.com: 4000 words

The downloader must handle failures due to network errors and timeouts. The only exception is that the HN API is assumed not to fail, for simplicity. However, handling HN API failure is a bonus.

  1. Regarding network failures, for simplicity this program should not retry in the face of errors, but instead fail gracefully by printing something to stdout.
  2. Regarding timeouts, the entire operation, from fetching URL to HTML to String Splitting must complete in 5 seconds. If not, the program should print an error message for that URL (but still continue with the other URLs).

Sample output:

https://exampleNetworkFailure.com: Error - Network failure
https://exampleTimeout.com: Timout - Operation not completed in 5 seconds.

The dataflow graph looks like this, for 2 URLs: Each arm of the graph is performed independently of the others.

      Obtain top 20 URLs from API
      _________________________
          |                 |
          |                 |
        URL 1             URL 2
          |                 |
          |                 |
         HTML              HTML
        |   |             |    |
        |   |             |    |
    Split  Split        Split  Split
        |   |             |    |
        |   |             |    |
        -----             ------
      Word Count         Word Count
          |                  |
          |                  |
          -------------------
                Queue
                  |
                Print to
                Console

How does this show Parallel vs Concurrency?

I have a WIP blog post about this.

concurrencyvsparallelsample's People

Contributors

thomastay avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.