HNHacker News
TopNewBestAskShowJobs

andonisus

379 karma · joined October 9, 2017

submissionscomments
andonisus··on Non-Blocking Parallelism for Services in Go
Doesn't this mean the caller may block if there are already the maximum number of inflight requests being run? I use the same type of pattern, but the core loop has a queue of input objects. The loop blocks waiting for input from either a caller or a go routine that completed. It enqueues the request from a caller, or lowers the inflight count from the complete signal. Then, it checks if we have capacity to run the request, and, if we do, dequeues the oldest request and submits it.

This means that the queue could grow unboundedly, but that is ok, as this type of structure is not meant for constant request handling but rather for bursts of requests that can happen asynchronously (and in parallel), and allows us to limit the maximum number that can run while also never blocking callers if there are no available go routines to process their request when submitted.

Here is a minimially-viable example of how I do it:

https://play.golang.org/p/mD_jpMdoY_g

Contents here:

package main

import ( "fmt" "time" "sync" )

func main() { fmt.Println("Hello, playground") wg := &sync.WaitGroup{} wg.Add(1) numRequests := 100

inCh := make(chan int) go func() { resCh := make(chan int) queue := []int{} inFlight := 0 max := 20 completed := 0

  for {
   select{
   case m := <- inCh:
    queue = append(queue, m)
    fmt.Println(fmt.Sprintf("Enqueing: %d", m))
   case <- resCh:
    inFlight -= 1
    completed += 1 
   }
   if len(queue) > 0 && inFlight < max {
    v := queue[0]
    queue = queue[1:]
    fmt.Println(fmt.Sprintf("Submitting: %d", v))
    inFlight += 1
    go func(_v int) {
     time.Sleep(1 * time.Second)
     fmt.Println(fmt.Sprintf("run: %d", _v))
     resCh <- v
    }(v)
   }
   if completed == numRequests {
    wg.Done()
   }
  }
 }()
 
 for i := 0; i < numRequests; i++ {
  inCh <- i
 }
 
 fmt.Println("Waiting for completion...")
 wg.Wait()
 fmt.Println("All processes completed. Exiting.")
}
andonisus··on Indoor Mapping Data Format
They likely see casinos as consumers of applications providing indoor wayfinding using this specification.
andonisus··on Trump administration announces overhaul of H1B visa program requiring higher pay
The difference is the H1B workers are taking jobs at the expense of Americans.
andonisus··on Even in Go, concurrency is still not easy
Here's how I like to do it:

https://play.golang.com/p/AB6exUIkNRg

Contents pasted below.

  package main

  import (
   "fmt"
   "sync"

  )

  func main() {
   wg := &sync.WaitGroup{}
   e := NewParallelExecutor(uint64(10))

  for i := 0; i < 100; i++ {
    wg.Add(1)
    func(_i int) {
     //make closure to capture i correctly
     e.Submit(func() {
      fmt.Println(_i)
      wg.Done()
     })
    }(i)

  }

  wg.Wait()
   fmt.Println("All done.")
  }

  type Executor interface {
   Submit(func())
  }

  type parallelExecutor struct {
   queue []func()
   inCh chan func()
   doneCh chan struct{}
  }

  func NewParallelExecutor(limit uint64) Executor {
   pe := &parallelExecutor{
    queue: make([]func(), 0, limit),
    inCh: make(chan func()),
    doneCh: make(chan struct{}),
   }

  go func() {
    running := uint64(0)
    for {
     select {
     case <- pe.doneCh:
      running -= 1
     case f := <- pe.inCh:
      pe.queue = append(pe.queue, f)
     }
     if len(pe.queue) > 0 && running < limit {
      running += 1
      fmt.Println(fmt.Sprintf("Goroutines in flight, waiting: %d | %d", running, len(pe.queue)))
      f := pe.queue[0]
      pe.queue = pe.queue[1:]
      go func(_f func()) {
       _f()
       pe.doneCh <- struct{}{}
      }(f)
     }
    }
   }()

  return pe
  }

  func (p *parallelExecutor) Submit(f func()) {
   p.inCh <- f
}
andonisus··on Even in Go, concurrency is still not easy
This does not run if you have more than 10K go routines :(
andonisus··on New case studies about Google’s use of Go
Efficient user-space threads (go routines) and the way go lends itself to the reactor pattern is exactly why is has been the language of choice for the company I work for. We use it to power all of our distributed microservices which process IoT packets from a stream. The performance and ease-of-use is heads and shoulders above everything else we tried before (mainly, Java with Kafka/Storm).
andonisus··on Riots and Political Theory: A Reading List
The problem with riots is they often get co-opted by actors whose goals are not in alignment with the goal of the original rioters. Also, there isn't usually a singular person, group, or entity who will take responsibility of the riots and say "We are rioting for XYZ reasons". Contrast this with peaceful protests, where the reasons for and goals of the protests are laid bare by its leaders. They are, in turn, able to promote their cause and have their grievances aired to the public at large. Finally, the destructive nature of riots poison the public perception of the rioters and their reasons, regardless of whatever just causes the rioters might have for their actions.
andonisus··on Networked games: Playing in the past or future
This seems like a good opportunity to share this semi-technical article which talks about rollback-based network code: https://ki.infil.net/w02-netcode.html

I found this article very interesting and took away a lot of different ideas around how state can be modeled efficiently for networked games.

andonisus··on Greatest Java apps
The Java version is still very popular due to its support for mods.
andonisus··on Mobilewalla used cellphone data to estimate the demographics of protesters
To what end is the targeting and profiling illegal? Simply having publicly-available analyzed is not illegal.
andonisus··on We should not defund the Terminator program
Then shouldn't they be saying "Reform the police"?
andonisus··on We should not defund the Terminator program
So say that. No part of the phrase "defund the police" indicates any part of this re-allocation that you describe. Regardless, you still will need a police force. There has to be some entity of the government which enforces the rule of law. Look at what happened when the police abandoned their posts in during the Rodney King riots. Additionally, what about homicide and detective units; we should probably keep those positions, right?

The problem with this slogan is I have no idea what it is actually proposing except for the literally dismantling of the police force as we know it.

andonisus··on We should not defund the Terminator program
This is such a stupid article. Cops are not terminators. If you really think society could function without entire police departments, I welcome you to lobby your local municipality to dismantle their police force. Unless, that is, you mean to tell me "Defund the police" doesn't actually mean defund the police, to which I say: say what you actually mean, and don't hide behind a catchy slogan.
andonisus··on Coronavirus will end the golden age for college towns
The programs are so expensive because there is such a large supply (or rather demand) from wealthy international students, even if they college or university is far less prestigious than this cost would otherwise suggest.
andonisus··on What every software engineer should know about Apache Kafka
Why would you be tied to the JVM by using Kinesis? You can write a client library for any language. We did it for Go.
andonisus··on Gears
So the force generated by the torque is completely unaffected by the mass of the lever? Then, why does applying the force on a longer portion of the lever create more torque? I had thought it was because there is more mass acting on the point of rotation (longer lever = more mass).
andonisus··on Gears
This may be a stupid question, but it is something I always wondered.

Torque is effective due to the mass of the lever having a force applied to it, right? Is the length of the lever being used as a stand-in for the mass being affected (a longer lever would necessarily have more mass)? If the lever had no mass, would there be no torque? If the lever did not have a uniform mass distribution, would the difference in applied torque differ based on where on the lever you applied the force (is the derivative of torque with respect to mass not constant for a non-uniform mass distribution)?

andonisus··on Why poor people make poor decisions
I've always thought it was unintended apathy. Making a (relatively) better choice will seemingly have no effect on lifting them out of poverty any time soon, so why bother? Do the thing that maximizes their pleasure, comfort, hope, etc. in the short term, because things are never going to change in the long term. This article seems to hint at this perspective when talking about not being able to take a break from poverty, but it never seems to make that leap.
andonisus··on Rocket League left behind on macOS and Linux due to DirectX 11 shift
We are not talking about Amazon, we are talking about Rocket League, which is nothing like Amazon; one is an online retailer and the other is a video game. Epic/Psyonix will be just fine. Lots of people spend money for the cosmetic items they offer.
andonisus··on Stack Overflow is forming a moderator council
[Put on Hold]
andonisus··on Stack Overflow is forming a moderator council
> The key to Stack Overflow’s future and growth are the millions of developers from around the world who find the site useful, but who haven’t yet been welcomed into the community. We need to expand our reach and engagement to ensure these developers join the conversation and push their own learning to new heights.

The key to stack overflow's future is providing useful answers to various programming questions, facilitating the asking and answering of these questions, and providing an easy way to find the answers to your questions.

andonisus··on A Sad Day for Rust
If you aren't satisfied with the code, fork it and fix it yourself. You are owed nothing. What right do people think they have to call someone out on it? Why do they feel entitled to other people's time and energy?
andonisus··on Education and Men without Work
What does this have to do with men?
andonisus··on A former Egyptian engineer found the secret to building a big gas-station chain
It very well could have an impact; who knows? I guess my point is that I feel that UI design should include UX as part of its guiding principles. You don't build a UI just to build a UI -- you build it to be used (hence, UX). How can you have UI without UX? Why does it therefore need to be a separate role? Shouldn't UI designers, by definition, include UX as part of their design? If your response to this question is that a UX designer would guide the UX of an entire platform, I could buy that. But that is not typically how a UX designer's role is described to me.
andonisus··on A former Egyptian engineer found the secret to building a big gas-station chain
Should I speak for everyone else? I cannot presume to share anything but my own personal experience. To that end, I am simply relating my experience with UX designers and the evangelists of it.
andonisus··on A former Egyptian engineer found the secret to building a big gas-station chain
I really don't buy any of the UX spiel that you laid out. I guess it depends on what kind of product you're buying, but I have never personally had a personal connection to any (technology) product. The only UX I care about is the application being responsive and doing what it says it's going to do. Additionally, I have never once recommended a product because it has evoked an emotional response for me.

To be clear, I am not saying that UX as whole is not needed, but I do not need someone who has made a career of it to elucidate me on the finer points of emotionally connecting with a user via tooltips and the like.

andonisus··on Developers join call for GitHub to cancel its ICE contract
Github's software is apolitical. This is not up for debate. Source code hosting is not a political thing.
andonisus··on Developers join call for GitHub to cancel its ICE contract
There are political consequences for everything we do. I never said there weren't any. All I said was that I don't think we should be concerned with the politics of selling apolitical software.
andonisus··on Developers join call for GitHub to cancel its ICE contract
Github provides software lifecycle management services. It is apolitical. I do not believe we should be trying to police the providers of apolitical software.
andonisus··on Advent of Code 2019
Here is my solution to Day 1 Part 2 in Go: https://play.golang.com/p/SQsCdTXk_YH
← PreviousPage 2 of 5Next →