Coder Social home page Coder Social logo

grafov / bcast Goto Github PK

View Code? Open in Web Editor NEW
99.0 99.0 16.0 48 KB

Broadcasting library for Go. Broadcast message of any type on a set of channels. WIP

License: BSD 3-Clause "New" or "Revised" License

Go 100.00%
broadcast-messages broadcasting library

bcast's People

Contributors

argami avatar brimstone avatar colonelpanic8 avatar grafov avatar matthewmcneely avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

bcast's Issues

[Go1.9] New release to satify `dep` tool

I use your awesome library for years, but when switching to go1.9 dep seems to favour a released version instead of the master branch - somehow makes sense. :)

Can you release a new version, so that it can be picked up?

question: what happends with read channel

So i have a piece of code:

for {                                                     
  msg := v.Recv()                                      
  c.Send(msg.(string))                               
}

What exactly happens when v(Member) closes? Will it infinitely block the reading? Because if it does, how this will affect my program, will GC recognize this as an infinitely blocking channel? Or what exactly happens?
So if something is smelly happens why not export some indicator that the Member is closed to stop this for loop?

Ordering of broadcast messages is not preserved

I believe that this is because there is a race condition at

bcast/bcast.go

Line 112 in 79e4f35

}

and

bcast/bcast.go

Line 150 in 79e4f35

}

I believe that what is happening is that sometimes go routines that were scheduled later than other goroutines by these lines for a given channel get called first.

I see three ways to approach fixing this:

Option 1 is to simply bite the bullet and call out to each member's channel synchronously.
Option 2 is to start using a logical clock for events and passing those values through to the consumer
Option 3 also involves a logical clock, but it hides it from consumers by having an intermediate goroutine/channel pair running for each member that handles ensuring that the events are properly serialized

Documentation is out of date

The README.md is no longer reflective of changes that seem to have been made in the past few days. I can see the pull request that was merged suggests a "massive refactor"... it would be quite useful to know what has actually changed and how to update my code.

broadcast

Hi,

can you select between buffered and unbuffered broadcasting channel?

I would like to send a broadcast message to routine1 and routine2 using a broadcast channel...

go receiveData() {
broadcast <- rcv
}

go routine1() {
msg := <- broadcast
}

go routine2() {
msg := <- broadcast
}

Thanks,
Gerald

Calling 'go group.Broadcasting(0)' results in tight loop

When invoking the Broadcasting method on a created Group with duration zero, the for loop in the function enters a tight loop. I believe this is because the test of

case <-time.After(timeout):

is always satisfied when timeout is zero. I tested out the addition of the following routine in my local build. When called the CPU usage is back to normal:

func (r *Group) ContinuousBroadcasting() {
    for {
        select {
        case received := <-r.in:
            switch received.payload.(type) {
            default: // receive a payload and broadcast it
                for _, member := range r.Members() {
                    if received.sender != member { // not return broadcast to sender

                        go func(out chan interface{}, received *Message) { // non blocking
                            out <- received.payload
                        }(member, &received)

                    }
                }
            }
        }
    }
}

Let me know if you want a pull request, or perhaps you'd like to refactor the select statement in Broadcasting yourself. BTW, love the package. Thanks!

Group function Leave return without memberLock unlocked

// Leave removes the provided member from the group
func (g *Group) Leave(leaving *Member) error {
	g.memberLock.Lock()
	memberIndex := -1
	for index, member := range g.members {
		if member == leaving {
			memberIndex = index
			break
		}
	}
	if memberIndex == -1 {
                // here, should unlock the lock
		return errors.New("Could not find provided memeber for removal")
	}
	g.members = append(g.members[:memberIndex], g.members[memberIndex+1:]...)
	leaving.close <- true // TODO: need to handle the case where there
	// is still stuff in this Members priorityQueue
	g.memberLock.Unlock()
	return nil
}

tests fail on Go 1.5.1

Hey there, I was looking into your bcast library and noticed some tests fail on my machine with Go 1.5.1:

dq@empit:bcast$ go test -v
=== RUN   TestNewGroupAndJoin
--- PASS: TestNewGroupAndJoin (0.00s)
=== RUN   TestUnjoin
--- PASS: TestUnjoin (0.00s)
=== RUN   TestBroadcast
--- FAIL: TestBroadcast (0.10s)
    bcast_test.go:85: not all messages broadcasted
=== RUN   TestBroadcastFromMember
--- FAIL: TestBroadcastFromMember (0.10s)
    bcast_test.go:114: not all messages broadcasted
=== RUN   TestGroupBroadcast
--- FAIL: TestGroupBroadcast (0.15s)
    bcast_test.go:141: not all messages broadcasted
=== RUN   TestBroadcastOnLargeNumberOfMembers
--- FAIL: TestBroadcastOnLargeNumberOfMembers (1.05s)
    bcast_test.go:168: not all messages broadcasted (11267/16256)
FAIL
exit status 1
FAIL    github.com/grafov/bcast 1.415s
dq@empit:bcast$ go version
go version go1.5.1 linux/amd64

cheers/

This library is buggy.

https://github.com/grafov/bcast/blob/master/bcast.go#L114

go func(out chan interface{}, received *Message) { // non blocking
     out <- received.payload
}(member, &received)

This code can block, and keep the goroutine around, effectively being a memory leak.

Along with other gotchas (like reordering the messages), and other race condition, it makes this library unsuitable for any serious usage.

While I appreciate your effort and know this software comes with no warranty, please indicate that this library is buggy in README, delete it or accept the PRs from various sources addressing problems with it.

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.