Skip to content

Fix event drop by fetching 3 pages with ETag optimization - #317

Open
emalaj-seq wants to merge 2 commits into
igrigorik:masterfrom
emalaj-seq:attempt-paging-fix
Open

Fix event drop by fetching 3 pages with ETag optimization#317
emalaj-seq wants to merge 2 commits into
igrigorik:masterfrom
emalaj-seq:attempt-paging-fix

Conversation

@emalaj-seq

Copy link
Copy Markdown

@igrigorik

Fixes #310

The previous commit f1f4200 changed PAGE_LIMIT from 500 to 100 (per GitHub API requirements) but only fetched a single page, causing an ~80% drop in captured events (from ~500 to ~100 per cycle).

This fix:

  • Fetches 5 pages in parallel (up to 500 events, matching original capacity)
  • Adds ETag-based conditional GET requests to minimize API usage
  • Skips polling cycles when page 1 returns 304 Not Modified
  • Automatically scales: only fetches pages that contain data
  • Updates Gemfile to use https:// instead of git:// protocol

Results:

  • Restores original 500 event capture capacity
  • Efficient API usage through ETag optimization
  • No more missed events during normal GitHub activity levels

emalaj-seq and others added 2 commits February 19, 2026 10:38
Fixes igrigorik#310

The previous commit f1f4200 changed PAGE_LIMIT from 500 to 100 (per GitHub
API requirements) but only fetched a single page, causing an ~80% drop in
captured events (from ~500 to ~100 per cycle).

This fix:
- Fetches 5 pages in parallel (up to 500 events, matching original capacity)
- Adds ETag-based conditional GET requests to minimize API usage
- Skips polling cycles when page 1 returns 304 Not Modified
- Automatically scales: only fetches pages that contain data
- Updates Gemfile to use https:// instead of git:// protocol

Results:
- Restores original 500 event capture capacity
- Efficient API usage through ETag optimization
- No more missed events during normal GitHub activity levels

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@emalaj-seq emalaj-seq changed the title Fix event drop by fetching 5 pages with ETag optimization Fix event drop by fetching 3 pages with ETag optimization Feb 27, 2026
@abhisheksoni27

Copy link
Copy Markdown

@igrigorik ?

@pombredanne pombredanne left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey :) Here are some quick review and suggestions from a bystander and nitpicker....
It has been a while since you submitted this and I think this can help. Are you still game to finish this?

Also an aside wrt. etags: given the volume of activities globally on the /events endpoint, when could there be a time where the etag would apply and avoid refetching? I fear that's never... but etags could be useful when adding support for focused per-org/user/repo event collection to backfill missing.

I am also wondering if we could use multiple keys and rotate them.

Comment thread crawler/crawler.rb
# If page 1 hasn't changed (304 Not Modified), skip this cycle
if req1.response_header.status == 304
@log.debug "Page 1 not modified, skipping"
EM.add_timer(0.2, &process)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What's the rationale for 0.2 seconds?

Comment thread crawler/crawler.rb
@file.close
end
@file = File.new(archive, "a+")
# If page 1 hasn't changed (304 Not Modified), skip this cycle

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is this a fact that if the 1st page is not modified, then 2 and 3 are not either?

Comment thread crawler/crawler.rb

@latest = []
@latest_key = lambda { |e| "#{e['id']}" }
@etags = {} # Track ETags for each page

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since tracking for each page, why not just use etag_1, etag_2 and etag_3?

Comment thread crawler/crawler.rb

StatHat.new.ez_count('Github Events', new_events.size)

EM.add_timer(0.2, &process)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What's the rationale for 0.2 secs?

Comment thread crawler/Gemfile

gem 'eventmachine', :git => 'git://github.com/eventmachine/eventmachine.git'
gem 'em-http-request', :git => 'git://github.com/igrigorik/em-http-request.git'
gem 'eventmachine', :git => 'https://github.com/eventmachine/eventmachine.git'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'd keep these changes in a separate PR.

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.

Drastic Drop Off in Events After 2025-05-23

3 participants