Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect nodes in parallel #67

Open
Stebalien opened this issue Aug 11, 2018 · 2 comments
Open

Connect nodes in parallel #67

Stebalien opened this issue Aug 11, 2018 · 2 comments
Labels
kind/enhancement A net-new feature or improvement to an existing feature

Comments

@Stebalien
Copy link
Member

See: #61 (comment)

@Stebalien Stebalien added the kind/enhancement A net-new feature or improvement to an existing feature label Aug 11, 2018
@davinci26
Copy link

What do you about either expanding or writing a function similar to mapWithOutput to do the connect calls in parallel. Its basically a combination of connectNodes with mapWithOutput

func mapConnectWithOutput(from, to []int, nodes []testbedi.Core, timeout time.Duration) ([]Result, error) {
	var wg sync.WaitGroup
	var lk sync.Mutex

	var results []Result

       	if err := validRange(to, len(nodes)); err != nil {
		return results, err
	}

	if err := validRange(from, len(nodes)); err != nil {
		return results, err
	}

	for _, f := range from {
		for _, t := range to {
			wg.Add(1)
			go func(from, to int, nodeFrom, nodeTo testbedi.Core) {
				defer wg.Done()
				ctx, cancel := context.WithTimeout(context.Background(), timeout)
				defer cancel()

				err := nodeFrom.Connect(ctx, nodeTo)

				lk.Lock()
				defer lk.Unlock()
				results = append(results, Result{
					Node:   from,
					Output: nil,
					Error:  errors.Wrapf(err, "node[%d] => node[%d]", from, to),
				})

			}(f, t, nodes[f], nodes[t])
		}
	}

	wg.Wait()
	return results, nil
}

It definitely needs testing and polishing but I think it conveys the idea.

Another idea is to use the mapListWithOutput that is under development in PR #75

What do you think?

@travisperson
Copy link
Member

We can probably throw that code into connectNodes. Returning the results is fine as well, I just wouldn't call it mapConnectWithOutput as it's not really a map like function (apply a function over an input).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement A net-new feature or improvement to an existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants