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

agent: remove an N^2 check. See #1265 #1296

Merged
merged 1 commit into from
Oct 26, 2015
Merged

agent: remove an N^2 check. See #1265 #1296

merged 1 commit into from
Oct 26, 2015

Conversation

armon
Copy link
Member

@armon armon commented Oct 13, 2015

In #1265, the theory we have is that there is some O(N^2) stuff happening. This was at least one obvious case of that, might be a partial fix.

@@ -389,16 +389,15 @@ func (l *localState) setSyncState() error {
l.serviceStatus[id] = syncStatus{inSync: equal}
}

// Index the remote health checks to improve efficiency
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change LGTM but in the thread and in the HC conversation he said there are no checks registered. I was expecting an n^2 services reconciliation here but I'm not seeing it.

@spheromak
Copy link

Just to clarify the code I saw the slowdown on was registering a TTL check.

Here is the method I have been using to register a service:

func (b *Binding) Register(client *discovery.ConsulClient) error {
    log.Println("registering binding ", b.UUID)
    siteServiceName := fmt.Sprintf("%s-%s-%s", b.Metadata.Site, b.Metadata.Type, b.Metadata.Environment)

    siteService := &api.AgentServiceRegistration{
      Name: siteServiceName,
      ID:   b.Metadata.Site,
      Tags: []string{b.UUID, b.Metadata.Environment},
      Port: b.Metadata.Port,

      Address: config.Opts.Bind,
    }

    siteCheck := &api.AgentCheckRegistration{
      ID:        b.UUID,
      Name:      fmt.Sprintf("%s-%s", b.Metadata.Type, b.UUID),
      ServiceID: b.Metadata.Site,
    }
    siteCheck.TTL = "15s"

    if err := client.Agent.ServiceRegister(siteService); err != nil {
      return err
    }

    if err := client.RegisterCheck(siteCheck); err != nil {
      return err
    }

    return nil
  }

and the generator:

  //Inject a boatload of bindings up front
  for i := 0; i < 100000; i++ {
    m := binding.Metadata{
      Site:        uniuri.New(),
      Type:        uniuri.New(),
      Environment: uniuri.New(),
      Port:        config.Opts.Port,
      Endpoint:    config.Opts.Bind,
    }

    bindings = append(bindings, binding.Binding{UUID: uuid.New(), Metadata: m})
  }

  for _, b := range bindings {
    if err := b.Register(&c); err != nil {
      log.Fatal(err)
    }
  }

slackpad added a commit that referenced this pull request Oct 26, 2015
@slackpad slackpad merged commit f6b589d into master Oct 26, 2015
@slackpad slackpad deleted the f-fast-sync branch October 26, 2015 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants