[GH-ISSUE #32] findLabel and the selector #171

Open
opened 2026-03-01 17:24:21 +03:00 by kerem · 3 comments
Owner

Originally created by @miekg on GitHub (Mar 9, 2013).
Original GitHub issue: https://github.com/abh/geodns/issues/32

The selector in findLabel generates garbage. It would be beter to completely remove this from this (often called) function.

Originally created by @miekg on GitHub (Mar 9, 2013). Original GitHub issue: https://github.com/abh/geodns/issues/32 The `selector` in findLabel generates garbage. It would be beter to completely remove this from this (often called) function.
Author
Owner

@abh commented on GitHub (Mar 10, 2013):

On Mar 8, 2013, at 23:46, Miek Gieben notifications@github.com wrote:

The selector in findLabel generates garbage. It would be beter to completely remove this from this (often called) function.

Using the new data structure we've talked about should fix that.

It's interesting (but makes sense) that "creating garbage" is a significant overhead. The things you pointed out also explains, I think, how the 32-bit servers ran out of memory so quickly when the query rate went way up.

Ask

<!-- gh-comment-id:14676856 --> @abh commented on GitHub (Mar 10, 2013): On Mar 8, 2013, at 23:46, Miek Gieben notifications@github.com wrote: > The selector in findLabel generates garbage. It would be beter to completely remove this from this (often called) function. Using the new data structure we've talked about should fix that. It's interesting (but makes sense) that "creating garbage" is a significant overhead. The things you pointed out also explains, I think, how the 32-bit servers ran out of memory so quickly when the query rate went way up. Ask
Author
Owner

@abh commented on GitHub (Nov 4, 2013):

Since you made this ticket I've dug myself deeper in, rather than working towards getting rid of it. Can you outline what you had in my for getting rid of it? Currently the code making the list of "targets" is in "GetTargets()" in targeting.go and serve.go passes that list to findLabels that then just iterates over it.

<!-- gh-comment-id:27665567 --> @abh commented on GitHub (Nov 4, 2013): Since you made this ticket I've dug myself deeper in, rather than working towards getting rid of it. Can you outline what you had in my for getting rid of it? Currently the code making the list of "targets" is in "GetTargets()" in targeting.go and serve.go passes that list to findLabels that then just iterates over it.
Author
Owner

@miekg commented on GitHub (Nov 4, 2013):

[ Quoting notifications@github.com in "Re: [geodns] findLabel and the sele..." ]

Since you made this ticket I've dug myself deeper in, rather than working towards getting rid of it. Can you outline what you had in my for getting rid of it? Currently the code making the list of "targets" is in "GetTargets()" in targeting.go and serve.go passes that list to findLabels that then just iterates over it.

Thought I mentioned it, because of the string var 'name', which probably
isn't a real big issue. The following patch captures what I had in mind
to change it. Note: untested! Only thing going for it, is that it
compiles.

grtz Miek
@@ -125,23 +125,30 @@ func (z _Zone) SoaRR() dns.RR {
// first available qType at each targeting level. Return a Label
// and the qtype that was "found"
func (z *Zone) findLabels(s string, targets []string, qts qTypes) (_Label, uint16) {

  • return z.findLabelsN(s, targets, qts, 0)
    +}

- for _, target := range targets {

  •   var name string
    
    +func (z _Zone) findLabelsN(s string, targets []string, qts qTypes, x int) (_Label, uint16) {
  • if x > 7 {
  •   return z.Labels[s], 0
    
  • }
  • name := make([]byte, 256)
  • for _, target := range targets {
    switch target {
    case "@":
  •       name = s
    
  •       copy(name, s)
    default:
        if len(s) > 0 {
    
  •           name = s + "." + target
    
  •           copy(name, s)
    
  •           name[len(s)+1] = '.'
    
  •           copy(name[:len(s)+2], target)
        } else {
    
  •           name = target
    
  •           copy(name, target)
        }
    }
    
  •   if label, ok := z.Labels[name]; ok {
    
  •   if label, ok := z.Labels[string(name)]; ok {
    
        for _, qtype := range qts {
    

@@ -153,9 +160,7 @@ func (z _Zone) findLabels(s string, targets []string, qts qTypes) (_Label, uint1
return z.Labels[s], qtype
case dns.TypeMF:
if label.Records[dns.TypeMF] != nil {

  •                   name = label.firstRR(dns.TypeMF).(*dns.MF).Mf
    
  •                   // TODO: need to avoid loops here somehow
    
  •                   return z.findLabels(name, targets, qts)
    
  •                   return z.findLabelsN(label.firstRR(dns.TypeMF).(*dns.MF).Mf, targets, qts, x+1)
                }
            default:
                // return the label if it has the right record
    
<!-- gh-comment-id:27676387 --> @miekg commented on GitHub (Nov 4, 2013): [ Quoting notifications@github.com in "Re: [geodns] findLabel and the sele..." ] > Since you made this ticket I've dug myself deeper in, rather than working towards getting rid of it. Can you outline what you had in my for getting rid of it? Currently the code making the list of "targets" is in "GetTargets()" in targeting.go and serve.go passes that list to findLabels that then just iterates over it. Thought I mentioned it, because of the string var 'name', which probably isn't a real big issue. The following patch captures what I had in mind to change it. Note: untested! Only thing going for it, is that it compiles. grtz Miek @@ -125,23 +125,30 @@ func (z _Zone) SoaRR() dns.RR { // first available qType at each targeting level. Return a Label // and the qtype that was "found" func (z *Zone) findLabels(s string, targets []string, qts qTypes) (_Label, uint16) { - return z.findLabelsN(s, targets, qts, 0) +} ## \- for _, target := range targets { - var name string +func (z _Zone) findLabelsN(s string, targets []string, qts qTypes, x int) (_Label, uint16) { - if x > 7 { - return z.Labels[s], 0 - } - name := make([]byte, 256) - for _, target := range targets { switch target { case "@": - name = s - copy(name, s) default: if len(s) > 0 { - name = s + "." + target - copy(name, s) - name[len(s)+1] = '.' - copy(name[:len(s)+2], target) } else { - name = target - ``` copy(name, target) } } ``` - ``` if label, ok := z.Labels[name]; ok { ``` - ``` if label, ok := z.Labels[string(name)]; ok { for _, qtype := range qts { ``` @@ -153,9 +160,7 @@ func (z _Zone) findLabels(s string, targets []string, qts qTypes) (_Label, uint1 return z.Labels[s], qtype case dns.TypeMF: if label.Records[dns.TypeMF] != nil { - name = label.firstRR(dns.TypeMF).(*dns.MF).Mf - // TODO: need to avoid loops here somehow - return z.findLabels(name, targets, qts) - return z.findLabelsN(label.firstRR(dns.TypeMF).(*dns.MF).Mf, targets, qts, x+1) } default: // return the label if it has the right record
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/geodns#171
No description provided.