The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Gungho::Component::Throttle.ja - スロットリング用ベースクラス

SYNOPSIS

  package Gungho::Component::Throttle::Domain;
  use base qw(Gungho::Component::Throttle);

DESCRIPTION

クローラー作成時には必ずリクエスト数を調整するスロットリングが必要になります。 このコンポーネントはスロットリングの親クラスとして機能します。実際の スロットリングはThrottle::SimpleやThrottle::Domainのような子クラスが行います。

Gungho::Component::Throttle::Simpleは単純に時間あたりのリクエスト総数を ベースにスロットリングを行います。どんなリクエストであっても時間あたりの リクエスト総数が規定値を上回った時点でスロットリングされます。

  # throttle down to 100 requests / hour
  components:
    - Throttle::Simple
  throttle:
    simple:
      max_iterms: 100
      interval: 3600

Gungho::Component::Throttle::Domainはホストネーム毎にスロットリングを行います。 ホスト毎に時間あたりのリクエスト総数が規定値を上回った時点でスロットリング されるようになります。

  # throttle down to 100 requests / host / hour
  components:
    - Throttle::Domain
  throttle:
    domain:
      max_iterms: 100
      interval: 3600

Throttle::DomainとThrottle::Simpleは内部的にData::Throttler、もしくは Data::Throttler::Memcachedを使用します。1台のホストでクローラーを動かしている 場合は普通のData::Throttlerで事足りますが、もし複数ホストでの運用を行う 場合はスロットリングデータを全てのホスト間で共有する必要があります。この場合は 設定でthrottlerタイプを指定し、memcachedバックエンドを使用する Data::Throttler::Memcachedを使用してください:

  components:
    - Throttle::Domain
  throttle:
    domain:
      throttler: Data::Throttler::Memcached
      cache:
        data: 127.0.0.1:11211
      max_items: 100
      interval: 3600

METHODS

feature_name

throttle

send_request

SEE ALSO

Gungho::Component::Throttle::Simple Gungho::Component::Throttle::Domain