<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Akshansh Gusain</title>
    <description>The latest articles on DEV Community by Akshansh Gusain (@gusain).</description>
    <link>https://dev.to/gusain</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F851588%2F3f144b90-b48d-49af-8763-ae42195a2c2a.JPG</url>
      <title>DEV Community: Akshansh Gusain</title>
      <link>https://dev.to/gusain</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gusain"/>
    <language>en</language>
    <item>
      <title>CSP - Oversimplified</title>
      <dc:creator>Akshansh Gusain</dc:creator>
      <pubDate>Tue, 13 Sep 2022 10:50:04 +0000</pubDate>
      <link>https://dev.to/gusain/csp-oversimplified-183o</link>
      <guid>https://dev.to/gusain/csp-oversimplified-183o</guid>
      <description>&lt;p&gt;CSP stands for communicating sequential processes which is a formal language for describing patterns of interaction in concurrent systems. First mentioned in Charles Antony Richard Hoare’s paper “Communicating Sequential Processes” in the Association for Computing Machinery(ACM). CSP is a simple concept of solving concurrency through two primitives of programming 1. Input 2. Output &lt;/p&gt;

&lt;p&gt;The paper abbreviates the term processes to any individual logic that needs input to run and produce output. (You can visualise this as a Goroutine) &lt;/p&gt;

&lt;p&gt;For communication between the processes, Hoare created input and output commands: ! for sending input into a process, and ? for reading output from a process. Each command had to specify either an output variable or a destination. Sometimes these two would refer to the same thing, in which case the two processes would be said to &lt;em&gt;correspond&lt;/em&gt;. In other words, output from one process would flow directly into the input of another process. &lt;em&gt;Go Channels&lt;/em&gt;! Sounds familiar? &lt;/p&gt;

&lt;p&gt;Go is the first language to incorporate principles from CSP in its core, and bring this style of concurrent programming to the masses.&lt;/p&gt;

</description>
      <category>go</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Websockets in Golang under 5 Minutes.</title>
      <dc:creator>Akshansh Gusain</dc:creator>
      <pubDate>Sat, 04 Jun 2022 15:49:31 +0000</pubDate>
      <link>https://dev.to/gusain/websockets-in-golang-under-5-minutes-5c7i</link>
      <guid>https://dev.to/gusain/websockets-in-golang-under-5-minutes-5c7i</guid>
      <description>&lt;h2&gt;
  
  
  Lets start with a simple http endpoint.
&lt;/h2&gt;

&lt;p&gt;Start off by building a simple HTTP server that returns Hello Devs whenever we hit it on port 8001. We’ll also define a simple HTTP endpoint that will act as the base of the WebSocket endpoint that we’ll be creating:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zsGOfXDk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uk0zvht40asp91uc6q7r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zsGOfXDk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uk0zvht40asp91uc6q7r.png" alt="Image description" width="880" height="1027"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Upgrading the HTTP Connection
&lt;/h2&gt;

&lt;p&gt;To create a WS endpoint we need to upgrade a standard HTTP connection to a WS connection. We'll be using &lt;em&gt;gorilla/websocket&lt;/em&gt; package for this.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Define the Upgrader&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This will hold information such as the Read and Write buffer size for our WS connection:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3KrQPXGv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pkj3houxrzrkwn28zcpy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3KrQPXGv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pkj3houxrzrkwn28zcpy.png" alt="Image description" width="880" height="367"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Take care of the CORS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This will determine whether or not an incoming request from a different domain is allowed to connect, and if it isn’t they’ll be hit with a CORS error. For now, we'll simply return true.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rUwxU-OX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/491rhsdwruk7887mpwir.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rUwxU-OX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/491rhsdwruk7887mpwir.png" alt="Image description" width="880" height="329"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Upgrading the Connection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We can now start attempting to upgrade the incoming HTTP connection using the upgrader.Upgrade() function which will take in the Response Writer and the pointer to the HTTP Request and return us with a pointer to a WebSocket connection, or an error if it failed to upgrade.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bLi7b9Xg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lyxemp7mr8xz6v4845uw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bLi7b9Xg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lyxemp7mr8xz6v4845uw.png" alt="Image description" width="880" height="443"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Start Listening
&lt;/h2&gt;

&lt;p&gt;Once the client is connected we can pass our WS to a reader function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0zN_NGc---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s72cfhdjpcx73tmgvt5a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0zN_NGc---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s72cfhdjpcx73tmgvt5a.png" alt="Image description" width="880" height="499"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;A simple echo reader: *&lt;/em&gt;&lt;br&gt;
A simple reader function that echos back every incoming message: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hbXHkLXj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rfmzzagjw18yuq2t2l1p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hbXHkLXj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rfmzzagjw18yuq2t2l1p.png" alt="Image description" width="880" height="616"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And that's it! We just created a WS endpoint in Go. &lt;/p&gt;

&lt;p&gt;Further reading: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.freecodecamp.org/news/million-websockets-and-go-cc58418460bb/"&gt;https://www.freecodecamp.org/news/million-websockets-and-go-cc58418460bb/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Find the code here:&lt;br&gt;
&lt;a href="https://gist.github.com/akshanshgusain/f2a797bc593136fd3484edb6d7401c50"&gt;https://gist.github.com/akshanshgusain/f2a797bc593136fd3484edb6d7401c50&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
    </item>
    <item>
      <title>Why I am considering Go</title>
      <dc:creator>Akshansh Gusain</dc:creator>
      <pubDate>Sat, 14 May 2022 12:45:51 +0000</pubDate>
      <link>https://dev.to/gusain/why-i-am-considering-go-5c8g</link>
      <guid>https://dev.to/gusain/why-i-am-considering-go-5c8g</guid>
      <description>&lt;p&gt;&lt;strong&gt;1. Never Really Liked Javascript&lt;/strong&gt;&lt;br&gt;
JS is a great language and I am grateful for it but its flaky at times there have been instances when it made my life hell! &lt;br&gt;
So when I heard about Go, I said to myself "Why not?!"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Relatively Easy to Learn&lt;/strong&gt;&lt;br&gt;
Its only my first week of learning Go and I already feel comfortable writing Go code. IMHO, if you have previous programming experience you should be up and running writing services in Go really quick.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Performance&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Go is simply quicker and does what Python or NodeJS does but better. Higher max IO, faster arithmetic faster general operation.&lt;/p&gt;

&lt;p&gt;But how fast?&lt;/p&gt;

&lt;p&gt;That's exactly i wanted to know so I ran benchmarks with FastAPI(Python), ExpressJS(NodeJS) and Gin(Go). &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test setup:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;8 Core CPU&lt;/em&gt;&lt;br&gt;
&lt;em&gt;8GB RAM&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;FastAPI with Uvicorn ASGI server scaled to 4 worker nodes with Gunicorn.(idk why but, when I tried to scale it more than 4 workers the performance got worse)&lt;/p&gt;

&lt;p&gt;ExpressJS with Cluster Module scaled to 8 cores.&lt;/p&gt;

&lt;p&gt;Go-Gin GOMAXPROCS=8.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My findings:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fukibel98r9t47qzli39z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fukibel98r9t47qzli39z.png" alt="FastAPI with Uvicorn ASGI server scaled to 4 worker nodes with Gunicorn"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fviaqmbwk53ev8952a6vr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fviaqmbwk53ev8952a6vr.png" alt="ExpressJS with Cluster Module scaled to 8 cores"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feb0mbh83ahy9vfulfdca.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feb0mbh83ahy9vfulfdca.png" alt="Go-Gin with single core"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>javascript</category>
      <category>python</category>
    </item>
  </channel>
</rss>
