{"action":"created","comment":{"url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/pulls/comments/77795513","id":77795513,"diff_hunk":"@@ -42,41 +41,36 @@ http {\n ### programmable configuration of DoS\n - `access_limiter.rb`\n ```ruby\n-####\n-threshold = 2\n-####\n-\n Server = get_server_class\n-r = Server::Request.new\n-cache = Userdata.new.shared_cache\n-global_mutex = Userdata.new.shared_mutex\n-\n-file = r.filename\n-\n-config = {\n-  # access limmiter by target\n-  :target => file,\n-}\n-\n-unless r.sub_request?\n-  limit = AccessLimiter.new r, cache, config\n-  # process-shared lock\n-  timeout = global_mutex.try_lock_loop(50000) do\n-    begin\n-      limit.increment\n-      Server.errlogger Server::LOG_NOTICE, \"access_limiter: file:#{r.filename} counter:#{limit.current}\"\n-      if limit.current > threshold\n-        Server.errlogger Server::LOG_NOTICE, \"access_limiter: file:#{r.filename} reached threshold: #{threshold}: return #{Server::HTTP_SERVICE_UNAVAILABLE}\"\n-        Server.return Server::HTTP_SERVICE_UNAVAILABLE\n+request = Server::Request.new\n+\n+unless request.sub_request?\n+  global_mutex = Userdata.new.shared_mutex\n+\n+  config = {\n+    :target => request.filename,","path":"README.md","position":58,"original_position":58,"commit_id":"8dcdf34972e8ca0948cd4ef072ebf1315cd0af76","original_commit_id":"8dcdf34972e8ca0948cd4ef072ebf1315cd0af76","user":{"login":"matsumoto-r","id":648437,"avatar_url":"https://avatars.githubusercontent.com/u/648437?v=3","gravatar_id":"","url":"https://api.github.com/users/matsumoto-r","html_url":"https://github.com/matsumoto-r","followers_url":"https://api.github.com/users/matsumoto-r/followers","following_url":"https://api.github.com/users/matsumoto-r/following{/other_user}","gists_url":"https://api.github.com/users/matsumoto-r/gists{/gist_id}","starred_url":"https://api.github.com/users/matsumoto-r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matsumoto-r/subscriptions","organizations_url":"https://api.github.com/users/matsumoto-r/orgs","repos_url":"https://api.github.com/users/matsumoto-r/repos","events_url":"https://api.github.com/users/matsumoto-r/events{/privacy}","received_events_url":"https://api.github.com/users/matsumoto-r/received_events","type":"User","site_admin":false},"body":"`request.filename`とかの`filename`メソッドは内部的に毎回構造体を見に行く処理が走るので、複数回`request.filename`を叩きたい場合は、基本的には先頭で変数に結果をいれておいて、変数で扱った方が高速です。","created_at":"2016-09-07T10:16:13Z","updated_at":"2016-09-07T10:16:13Z","html_url":"https://github.com/matsumoto-r/http-access-limiter/pull/1#discussion_r77795513","pull_request_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/matsumoto-r/http-access-limiter/pulls/comments/77795513"},"html":{"href":"https://github.com/matsumoto-r/http-access-limiter/pull/1#discussion_r77795513"},"pull_request":{"href":"https://api.github.com/repos/matsumoto-r/http-access-limiter/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/pulls/1","id":83019688,"html_url":"https://github.com/matsumoto-r/http-access-limiter/pull/1","diff_url":"https://github.com/matsumoto-r/http-access-limiter/pull/1.diff","patch_url":"https://github.com/matsumoto-r/http-access-limiter/pull/1.patch","issue_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/issues/1","number":1,"state":"open","locked":false,"title":"[WIP] 制限対象と閾値、制限を行う時間帯をvedisで制御できるようにした","user":{"login":"takumakume","id":10905048,"avatar_url":"https://avatars.githubusercontent.com/u/10905048?v=3","gravatar_id":"","url":"https://api.github.com/users/takumakume","html_url":"https://github.com/takumakume","followers_url":"https://api.github.com/users/takumakume/followers","following_url":"https://api.github.com/users/takumakume/following{/other_user}","gists_url":"https://api.github.com/users/takumakume/gists{/gist_id}","starred_url":"https://api.github.com/users/takumakume/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/takumakume/subscriptions","organizations_url":"https://api.github.com/users/takumakume/orgs","repos_url":"https://api.github.com/users/takumakume/repos","events_url":"https://api.github.com/users/takumakume/events{/privacy}","received_events_url":"https://api.github.com/users/takumakume/received_events","type":"User","site_admin":false},"body":"## 本PRでの変更点\r\n\r\n### 制限対象と閾値、制限を行う時間帯をvedisで制御できるようにした\r\n\r\n- ファイル毎に制限値、制限を有効にする時間帯を設定できるようにし、その条件を [vedis](http://vedis.symisc.net) に予め登録された情報を元に行えるようにした。\r\n- リクエスト毎に [mruby-vedis](https://github.com/matsumoto-r/mruby-vedis) を利用して、 [vedis](http://vedis.symisc.net) にアクセスする。\r\n  - key と value は以下のような構造\r\n    ```ruby\r\n    # Key\r\n    \"/var/www/html/test1.php\"\r\n\r\n    # Value\r\n    {\r\n      \"max_clients\" => 1, \r\n      \"time_slots\"  => [\r\n        { \"begin\" => 900,  \"end\" => 1000 }, \r\n        { \"begin\" => 1700, \"end\" => 2000 },\r\n      ]\r\n    }\r\n```\r\n\r\n  - max_clients : 同時アクセス数の上限値\r\n  - time_slots  : 制限を有効にする時間 (設定しなければ常に制限を有効化)\r\n- vedisに値を登録するツールは別途開発\r\n\r\n### AccessLimiterのテストコードを追加\r\n\r\n- [mruby-mtest](https://github.com/iij/mruby-mtest) を使用したテストコードを追加しており、 `rake` を実行することでDocker上でテストをすることが可能。","created_at":"2016-08-28T16:05:55Z","updated_at":"2016-09-07T10:16:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0a6a5a3440335e578c815e365053669d3aa816f8","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/pulls/1/commits","review_comments_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/pulls/1/comments","review_comment_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/pulls/comments{/number}","comments_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/issues/1/comments","statuses_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/statuses/8dcdf34972e8ca0948cd4ef072ebf1315cd0af76","head":{"label":"takumakume:dynamic_configration","ref":"dynamic_configration","sha":"8dcdf34972e8ca0948cd4ef072ebf1315cd0af76","user":{"login":"takumakume","id":10905048,"avatar_url":"https://avatars.githubusercontent.com/u/10905048?v=3","gravatar_id":"","url":"https://api.github.com/users/takumakume","html_url":"https://github.com/takumakume","followers_url":"https://api.github.com/users/takumakume/followers","following_url":"https://api.github.com/users/takumakume/following{/other_user}","gists_url":"https://api.github.com/users/takumakume/gists{/gist_id}","starred_url":"https://api.github.com/users/takumakume/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/takumakume/subscriptions","organizations_url":"https://api.github.com/users/takumakume/orgs","repos_url":"https://api.github.com/users/takumakume/repos","events_url":"https://api.github.com/users/takumakume/events{/privacy}","received_events_url":"https://api.github.com/users/takumakume/received_events","type":"User","site_admin":false},"repo":{"id":65355622,"name":"http-access-limiter","full_name":"takumakume/http-access-limiter","owner":{"login":"takumakume","id":10905048,"avatar_url":"https://avatars.githubusercontent.com/u/10905048?v=3","gravatar_id":"","url":"https://api.github.com/users/takumakume","html_url":"https://github.com/takumakume","followers_url":"https://api.github.com/users/takumakume/followers","following_url":"https://api.github.com/users/takumakume/following{/other_user}","gists_url":"https://api.github.com/users/takumakume/gists{/gist_id}","starred_url":"https://api.github.com/users/takumakume/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/takumakume/subscriptions","organizations_url":"https://api.github.com/users/takumakume/orgs","repos_url":"https://api.github.com/users/takumakume/repos","events_url":"https://api.github.com/users/takumakume/events{/privacy}","received_events_url":"https://api.github.com/users/takumakume/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/takumakume/http-access-limiter","description":"Count the number of references to the requested file on Apache and Nginx using mruby code.","fork":true,"url":"https://api.github.com/repos/takumakume/http-access-limiter","forks_url":"https://api.github.com/repos/takumakume/http-access-limiter/forks","keys_url":"https://api.github.com/repos/takumakume/http-access-limiter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/takumakume/http-access-limiter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/takumakume/http-access-limiter/teams","hooks_url":"https://api.github.com/repos/takumakume/http-access-limiter/hooks","issue_events_url":"https://api.github.com/repos/takumakume/http-access-limiter/issues/events{/number}","events_url":"https://api.github.com/repos/takumakume/http-access-limiter/events","assignees_url":"https://api.github.com/repos/takumakume/http-access-limiter/assignees{/user}","branches_url":"https://api.github.com/repos/takumakume/http-access-limiter/branches{/branch}","tags_url":"https://api.github.com/repos/takumakume/http-access-limiter/tags","blobs_url":"https://api.github.com/repos/takumakume/http-access-limiter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/takumakume/http-access-limiter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/takumakume/http-access-limiter/git/refs{/sha}","trees_url":"https://api.github.com/repos/takumakume/http-access-limiter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/takumakume/http-access-limiter/statuses/{sha}","languages_url":"https://api.github.com/repos/takumakume/http-access-limiter/languages","stargazers_url":"https://api.github.com/repos/takumakume/http-access-limiter/stargazers","contributors_url":"https://api.github.com/repos/takumakume/http-access-limiter/contributors","subscribers_url":"https://api.github.com/repos/takumakume/http-access-limiter/subscribers","subscription_url":"https://api.github.com/repos/takumakume/http-access-limiter/subscription","commits_url":"https://api.github.com/repos/takumakume/http-access-limiter/commits{/sha}","git_commits_url":"https://api.github.com/repos/takumakume/http-access-limiter/git/commits{/sha}","comments_url":"https://api.github.com/repos/takumakume/http-access-limiter/comments{/number}","issue_comment_url":"https://api.github.com/repos/takumakume/http-access-limiter/issues/comments{/number}","contents_url":"https://api.github.com/repos/takumakume/http-access-limiter/contents/{+path}","compare_url":"https://api.github.com/repos/takumakume/http-access-limiter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/takumakume/http-access-limiter/merges","archive_url":"https://api.github.com/repos/takumakume/http-access-limiter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/takumakume/http-access-limiter/downloads","issues_url":"https://api.github.com/repos/takumakume/http-access-limiter/issues{/number}","pulls_url":"https://api.github.com/repos/takumakume/http-access-limiter/pulls{/number}","milestones_url":"https://api.github.com/repos/takumakume/http-access-limiter/milestones{/number}","notifications_url":"https://api.github.com/repos/takumakume/http-access-limiter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/takumakume/http-access-limiter/labels{/name}","releases_url":"https://api.github.com/repos/takumakume/http-access-limiter/releases{/id}","deployments_url":"https://api.github.com/repos/takumakume/http-access-limiter/deployments","created_at":"2016-08-10T06:15:10Z","updated_at":"2016-08-10T06:15:12Z","pushed_at":"2016-09-06T05:09:25Z","git_url":"git://github.com/takumakume/http-access-limiter.git","ssh_url":"git@github.com:takumakume/http-access-limiter.git","clone_url":"https://github.com/takumakume/http-access-limiter.git","svn_url":"https://github.com/takumakume/http-access-limiter","homepage":"","size":31,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"matsumoto-r:master","ref":"master","sha":"3cb60f79a8815c97c100c35caafb2489cf6128a2","user":{"login":"matsumoto-r","id":648437,"avatar_url":"https://avatars.githubusercontent.com/u/648437?v=3","gravatar_id":"","url":"https://api.github.com/users/matsumoto-r","html_url":"https://github.com/matsumoto-r","followers_url":"https://api.github.com/users/matsumoto-r/followers","following_url":"https://api.github.com/users/matsumoto-r/following{/other_user}","gists_url":"https://api.github.com/users/matsumoto-r/gists{/gist_id}","starred_url":"https://api.github.com/users/matsumoto-r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matsumoto-r/subscriptions","organizations_url":"https://api.github.com/users/matsumoto-r/orgs","repos_url":"https://api.github.com/users/matsumoto-r/repos","events_url":"https://api.github.com/users/matsumoto-r/events{/privacy}","received_events_url":"https://api.github.com/users/matsumoto-r/received_events","type":"User","site_admin":false},"repo":{"id":38476558,"name":"http-access-limiter","full_name":"matsumoto-r/http-access-limiter","owner":{"login":"matsumoto-r","id":648437,"avatar_url":"https://avatars.githubusercontent.com/u/648437?v=3","gravatar_id":"","url":"https://api.github.com/users/matsumoto-r","html_url":"https://github.com/matsumoto-r","followers_url":"https://api.github.com/users/matsumoto-r/followers","following_url":"https://api.github.com/users/matsumoto-r/following{/other_user}","gists_url":"https://api.github.com/users/matsumoto-r/gists{/gist_id}","starred_url":"https://api.github.com/users/matsumoto-r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matsumoto-r/subscriptions","organizations_url":"https://api.github.com/users/matsumoto-r/orgs","repos_url":"https://api.github.com/users/matsumoto-r/repos","events_url":"https://api.github.com/users/matsumoto-r/events{/privacy}","received_events_url":"https://api.github.com/users/matsumoto-r/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/matsumoto-r/http-access-limiter","description":"Count the number of references to the requested file on Apache and Nginx using mruby code.","fork":false,"url":"https://api.github.com/repos/matsumoto-r/http-access-limiter","forks_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/forks","keys_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/teams","hooks_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/hooks","issue_events_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/issues/events{/number}","events_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/events","assignees_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/assignees{/user}","branches_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/branches{/branch}","tags_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/tags","blobs_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/git/refs{/sha}","trees_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/statuses/{sha}","languages_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/languages","stargazers_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/stargazers","contributors_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/contributors","subscribers_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/subscribers","subscription_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/subscription","commits_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/commits{/sha}","git_commits_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/git/commits{/sha}","comments_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/comments{/number}","issue_comment_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/issues/comments{/number}","contents_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/contents/{+path}","compare_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/merges","archive_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/downloads","issues_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/issues{/number}","pulls_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/pulls{/number}","milestones_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/milestones{/number}","notifications_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/labels{/name}","releases_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/releases{/id}","deployments_url":"https://api.github.com/repos/matsumoto-r/http-access-limiter/deployments","created_at":"2015-07-03T06:33:29Z","updated_at":"2016-07-29T03:20:09Z","pushed_at":"2016-09-06T05:09:26Z","git_url":"git://github.com/matsumoto-r/http-access-limiter.git","ssh_url":"git@github.com:matsumoto-r/http-access-limiter.git","clone_url":"https://github.com/matsumoto-r/http-access-limiter.git","svn_url":"https://github.com/matsumoto-r/http-access-limiter","homepage":"","size":7,"stargazers_count":7,"watchers_count":7,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/matsumoto-r/http-access-limiter/pulls/1"},"html":{"href":"https://github.com/matsumoto-r/http-access-limiter/pull/1"},"issue":{"href":"https://api.github.com/repos/matsumoto-r/http-access-limiter/issues/1"},"comments":{"href":"https://api.github.com/repos/matsumoto-r/http-access-limiter/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/matsumoto-r/http-access-limiter/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/matsumoto-r/http-access-limiter/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/matsumoto-r/http-access-limiter/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/matsumoto-r/http-access-limiter/statuses/8dcdf34972e8ca0948cd4ef072ebf1315cd0af76"}}}}
{"actor":{"display_login":"matsumoto-r"}}