Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
bridgestrap
bridgestrap
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3
    • Issues 3
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 0
    • Merge Requests 0
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards

GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

  • The Tor Project
  • Anti-censorship
  • bridgestrapbridgestrap
  • Issues
  • #1

Closed
Open
Opened Sep 30, 2020 by Philipp Winter@phwOwner

Use timers to determine when it's time to prune cache entries

Each time a new cache entry is added, bridgestrap iterates over existing cache entries to figure out what entries have expired:

// First, prune expired cache entries.                                      
now := time.Now()                                                           
cacheMutex.Lock()                                                           
for index, entry := range *tc {                                             
    if entry.Time.Before(now.Add(-CacheValidity)) {                         
        delete(*tc, index)                                                  
    }                                                                       
}

This scales linearly, which is bad news. On my core i7 2.9 GHz laptop, it takes 0.3 ms to prune a cache holding 10,000 elements. @cohosh suggested that we could use Timers instead: each time a cache entry is added, we set up a new timer. In parallel, we have a goroutine running that waits for the timers to fire, to then delete the expired cache entries.

Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: tpo/anti-censorship/bridgestrap#1