Skip to content

Instantly share code, notes, and snippets.

View WhisperingChaos's full-sized avatar

Rich Moyse WhisperingChaos

View GitHub Profile
@WhisperingChaos
WhisperingChaos / #Trace Latency Gaps
Last active February 11, 2022 19:24
Trace Latency Gaps
We couldn’t find that file to show.
@WhisperingChaos
WhisperingChaos / Ping.go
Last active October 16, 2018 02:31
Alternative to Synchronization queues in Golang
package main
import (
"fmt"
"math/rand"
"strconv"
"sync"
"time"
)
@WhisperingChaos
WhisperingChaos / HypervUuntuModule.txt
Last active July 17, 2018 20:19
Hyper-V Ubuntu Module for Integration Services
description: Hyper-V Sockets
srcversion: 4EC78A1B60598CC0FEB9FC2
name: hv_sock
description: Microsoft Hyper-V network driver
srcversion: 852146352704FB30084A3F3
name: hv_netvsc
description: Hyper-V Utilities
srcversion: 3B8AC762BA4858730251E7E
@WhisperingChaos
WhisperingChaos / PingShared.go
Created April 18, 2018 00:53
Goroutine order problem
package main
import (
"fmt"
"strconv"
)
// An alternative to "Synchronization queues in Golang" (https://medium.com/golangspec/synchronization-queues-in-golang-554f8e3a31a4)
// See goplayground ()
func main() {
@WhisperingChaos
WhisperingChaos / orderImplicit.go
Last active April 18, 2018 00:49
Exploring implicit goroutine ordering and selection from queue.
package main
/*
Exploring goroutine ordering imposed by runtime scheduling. The
situation encoded below consists of a single synchronous writer and two
concurrent readers. The readers are connected to the writer via a single
unbuffered shared channel. A
selection of "next" goroutine from runtime scheduling queue. Trying
to enforce "fairness" whose meaning in this situation guarantees execution
of all goroutines, avoiding goroutine starvation/barging explained
@WhisperingChaos
WhisperingChaos / orderExplicitHappenBefore.go
Last active April 17, 2018 13:37
Exploring goroutine ordering explicit happen before.
package main
/*
Exploring concept of "Happens Before" using channels to impose order on
selection of "next" goroutine from runtime scheduling queue. Trying
to enforce "fairness" whose meaning in this situation guarantees execution
of all goroutines, avoiding goroutine starvation/barging explained
here: https://github.com/golang/go/issues/11506.
go PlayGound: https://play.golang.org/p/4sGKDepzqaV
*/
func consumeOrderedByAffectingProbability(msg_1ch chan msg_1, msg_2ch chan msg_2) {
// implement priorty function that selects messages from msg_2ch twice as often
// as msg_1ch by affecting the probability function of the select
// statement. produces outcome whose message type totals are equivalent to
// nil bias function but using simpler encoding.
for msgCnt := 0; msgCnt < 21; msgCnt++ {
select {
case msg, ok := <-msg_1ch:
if ok {
msg.msgType()
@WhisperingChaos
WhisperingChaos / NilChannelFavorCompleteSolution.go
Last active February 15, 2018 12:16
Nil Channel favor/bias channels: Complete Solution
package main
import (
"fmt"
)
type msg_1 struct {
}
func (msg_1) msgType() {
@WhisperingChaos
WhisperingChaos / OrderedAccordingToChannelSemantics.go
Last active February 15, 2018 12:12
Nil Channel favor/bias channels:
func consumeAccordingToChannelSemantics(msg_1ch chan msg_1, msg_2ch chan msg_2) {
// because the channels were asychronous and completely full
// before running this routine, select's channel semantics
// considers the messages as having arrived at the same time.
// select therefore randomly reads one of the channels. since
// only two case statements, probability of selection is
// equivalent to a random coin toss.
for msgCnt := 0; msgCnt < 21; msgCnt++ {
select {
case msg, ok := <-msg_1ch:
@WhisperingChaos
WhisperingChaos / orderByBias.go
Created February 15, 2018 03:45
Nil Channel favor/prioritize channels: order by bias
func consumeOrderedByBias(msg_1ch chan msg_1, msg_2ch chan msg_2) {
// copy channels to enable their restoration
msg_1_save := msg_1ch
msg_2_save := msg_2ch
// bias function encoded as a for loop
for msgCnt := 0; msgCnt < 21; msgCnt++ {
// use modulus math to help implement bias function
if msgCnt%3 == 0 {
// favor channel 1 when processing muliples of 3