{"action":"created","comment":{"url":"https://api.github.com/repos/2600hz/kazoo/pulls/comments/195503035","pull_request_review_id":128886167,"id":195503035,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5NTUwMzAzNQ==","diff_hunk":"@@ -262,3 +267,157 @@ flush_cache_docs(Db, Docs, Options) ->\n          || Doc <- Docs\n         ],\n     'ok'.\n+\n+-spec load_test() -> 'true'.\n+load_test() ->\n+    load_test(100, 50).\n+\n+-spec load_test(pos_integer(), pos_integer()) -> 'ok'.\n+load_test(NumOfAgents, MaxMsgs) when NumOfAgents > 0\n+                                     andalso MaxMsgs > 0 ->\n+    DbName = <<\"cache_load_tests\">>,\n+    CacheProps = [{'origin_bindings', []}],\n+    %% Start the cache process with `origin_bindings' declared so we get a\n+    %% gen_listener process.\n+    {'ok', CachePid} = kz_cache:start_link(binary_to_atom(DbName, 'utf8'), CacheProps),\n+    %% Make sure the cache process has 0 queued messages.\n+    {'message_queue_len', 0} = process_info(CachePid, 'message_queue_len'),\n+    StartTime = kz_time:now_ms(), % Used to calculate the uptime.\n+    %% Spawn agent(s) to simulate load.\n+    Self = self(),\n+    Fun = fun() -> load_test_agent(CachePid, DbName, MaxMsgs, Self, 0) end,\n+    Spawns = [spawn_monitor(Fun) || _  <- lists:seq(1, NumOfAgents)],\n+    %% Wait for all the agents to finish, this way we know none of the agents got stuck\n+    %% or timed out.\n+    'ok' = wait_for(Spawns),\n+    %% Calculate msg rate per agent.\n+    UptimeMS = kz_time:elapsed_ms(StartTime, kz_time:now_ms()),\n+    Loops = collect_loops(0), % All agents' loops count\n+    MsgRate = (2 * Loops) / UptimeMS,\n+    lager:info(\"Uptime: ~pms, TotalLoops: ~p\", [UptimeMS, Loops]),\n+    lager:info(\"MsgRate: ~.2f\", [MsgRate]),\n+    'ok' = kz_cache:stop_local(CachePid).\n+\n+-spec load_test_agent(pid(), kz_term:text(), pos_integer(), pid(), non_neg_integer()) ->\n+    'no_return'.\n+load_test_agent(CachePid, DbName, MaxMsgs, Parent, LoopCount) ->\n+    %% Check that there is some space in he queue before sending a new msg\n+    PInfoKey = 'message_queue_len',\n+    case process_info(CachePid, PInfoKey) of\n+        {PInfoKey, N} when N < MaxMsgs ->\n+            'ok';\n+        {PInfoKey, N} ->\n+            lager:error(\"Cache already has ~p queued messages, exiting (~p loops)\",\n+                        [N, LoopCount]),\n+            Parent ! {'loops', self(), LoopCount},\n+            exit('normal')\n+    end,\n+    %% Insert a key/value pair into the cache.\n+    DocId = kz_binary:rand_hex(16),\n+    Type = 'undefined',\n+    Category = <<\"configuration\">>,\n+    AMQPPayload = load_test_build_amqp_payload(<<\"doc_created\">>, DbName, Type, DocId, Category),\n+    Payload = #cache_obj{'key'=DocId\n+                        ,'value'=AMQPPayload\n+                        ,'expires'=1000\n+                        ,'callback'='undefined'\n+                        ,'origin'={'db', DbName, DocId}\n+                        },\n+    CachePid ! {'$gen_call', {self(), make_ref()}, Payload},\n+    %% Flush the agent's mailbox (because of the '$gen_call').\n+    'ok' = receive after 0 -> 'ok' end,\n+    %% \"doc edited\"\n+    'ok' = load_test_publish(CachePid, <<\"doc_edited\">>, DbName, Type, DocId, Category),\n+    load_test_agent(CachePid, DbName, MaxMsgs, Parent, LoopCount + 1).\n+\n+-spec wait_for([] | [{pid(), reference()}]) -> 'ok' | 'no_return'.\n+wait_for([]) ->\n+    'ok';\n+wait_for([{Pid, Ref} | Spawns]) ->\n+    receive\n+        {'DOWN', Ref, 'process', Pid, 'normal'} ->\n+            wait_for(Spawns)\n+        after 1000 ->\n+            lager:error(\"~p failed to return, ~p workers left.\", [Pid, length(Spawns)]),\n+            exit(\"Failed to return\")\n+    end.\n+\n+-spec collect_loops(non_neg_integer()) -> pos_integer().\n+collect_loops(CurrentCount) ->\n+    receive\n+        {'loops', _Pid, LoopCount} ->\n+            collect_loops(CurrentCount + LoopCount)\n+    after 1000 ->\n+        CurrentCount\n+    end.\n+\n+-spec load_test_publish(pid()\n+                       ,kz_term:ne_binary()\n+                       ,kz_term:ne_binary()\n+                       ,kz_term:ne_binary()\n+                       ,kz_term:ne_binary()\n+                       ,kz_term:ne_binary()) -> 'ok'.\n+load_test_publish(CachePid, EvName, Db, EvType, Id, Category) ->\n+    RKey = binary:list_to_bin(lists:join(<<\".\">>, [EvName, Db, kz_term:to_binary(EvType), Id])),\n+    BD = load_test_build_bd(Category, RKey),\n+    PBasic = load_test_build_pbasic(),\n+    Payload = load_test_build_amqp_payload(EvName, Db, EvType, Id, Category),\n+    CachePid ! {BD, #amqp_msg{'props'=PBasic, 'payload'=kz_json:encode(Payload)}},\n+    'ok'.\n+\n+-spec load_test_build_bd(kz_term:ne_binary(), kz_term:ne_binary()) -> #'basic.deliver'{}.\n+load_test_build_bd(Category, RKey) ->\n+    #'basic.deliver'\n+    {'consumer_tag' = kz_binary:rand_hex(16)\n+    ,'delivery_tag' = rand:uniform(1000)\n+    ,'exchange' = Category\n+    ,'routing_key' = RKey\n+    }.\n+\n+-spec load_test_build_pbasic() -> #'P_basic'{}.\n+load_test_build_pbasic() ->\n+    #'P_basic'\n+    {'content_type' = <<\"application/json\">>\n+    ,'content_encoding' = 'undefined'","path":"core/kazoo_data/src/kzs_cache.erl","position":131,"original_position":131,"commit_id":"f43df60020be206454414e4c361dd168944e9ed2","original_commit_id":"fc34c1301b4f328ee70cf305dc713a05c623b65d","user":{"login":"harenson","id":216031,"node_id":"MDQ6VXNlcjIxNjAzMQ==","avatar_url":"https://avatars0.githubusercontent.com/u/216031?v=4","gravatar_id":"","url":"https://api.github.com/users/harenson","html_url":"https://github.com/harenson","followers_url":"https://api.github.com/users/harenson/followers","following_url":"https://api.github.com/users/harenson/following{/other_user}","gists_url":"https://api.github.com/users/harenson/gists{/gist_id}","starred_url":"https://api.github.com/users/harenson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harenson/subscriptions","organizations_url":"https://api.github.com/users/harenson/orgs","repos_url":"https://api.github.com/users/harenson/repos","events_url":"https://api.github.com/users/harenson/events{/privacy}","received_events_url":"https://api.github.com/users/harenson/received_events","type":"User","site_admin":false},"body":"Done, thanks 👍 ","created_at":"2018-06-14T17:14:12Z","updated_at":"2018-06-14T17:14:13Z","html_url":"https://github.com/2600hz/kazoo/pull/4898#discussion_r195503035","pull_request_url":"https://api.github.com/repos/2600hz/kazoo/pulls/4898","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/2600hz/kazoo/pulls/comments/195503035"},"html":{"href":"https://github.com/2600hz/kazoo/pull/4898#discussion_r195503035"},"pull_request":{"href":"https://api.github.com/repos/2600hz/kazoo/pulls/4898"}},"in_reply_to_id":194581224},"pull_request":{"url":"https://api.github.com/repos/2600hz/kazoo/pulls/4898","id":193086552,"node_id":"MDExOlB1bGxSZXF1ZXN0MTkzMDg2NTUy","html_url":"https://github.com/2600hz/kazoo/pull/4898","diff_url":"https://github.com/2600hz/kazoo/pull/4898.diff","patch_url":"https://github.com/2600hz/kazoo/pull/4898.patch","issue_url":"https://api.github.com/repos/2600hz/kazoo/issues/4898","number":4898,"state":"open","locked":false,"title":"[WIP - DON'T MERGE] KAZOO-5905: Split kz_cache and gen_listener functionality into separate modules","user":{"login":"harenson","id":216031,"node_id":"MDQ6VXNlcjIxNjAzMQ==","avatar_url":"https://avatars0.githubusercontent.com/u/216031?v=4","gravatar_id":"","url":"https://api.github.com/users/harenson","html_url":"https://github.com/harenson","followers_url":"https://api.github.com/users/harenson/followers","following_url":"https://api.github.com/users/harenson/following{/other_user}","gists_url":"https://api.github.com/users/harenson/gists{/gist_id}","starred_url":"https://api.github.com/users/harenson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harenson/subscriptions","organizations_url":"https://api.github.com/users/harenson/orgs","repos_url":"https://api.github.com/users/harenson/repos","events_url":"https://api.github.com/users/harenson/events{/privacy}","received_events_url":"https://api.github.com/users/harenson/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-06-06T17:29:02Z","updated_at":"2018-06-14T17:14:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f1b4c650385984935ed240ea3e4adcfbc1030603","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/2600hz/kazoo/pulls/4898/commits","review_comments_url":"https://api.github.com/repos/2600hz/kazoo/pulls/4898/comments","review_comment_url":"https://api.github.com/repos/2600hz/kazoo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/2600hz/kazoo/issues/4898/comments","statuses_url":"https://api.github.com/repos/2600hz/kazoo/statuses/f43df60020be206454414e4c361dd168944e9ed2","head":{"label":"2600hz:KAZOO-5905","ref":"KAZOO-5905","sha":"f43df60020be206454414e4c361dd168944e9ed2","user":{"login":"2600hz","id":408801,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQwODgwMQ==","avatar_url":"https://avatars3.githubusercontent.com/u/408801?v=4","gravatar_id":"","url":"https://api.github.com/users/2600hz","html_url":"https://github.com/2600hz","followers_url":"https://api.github.com/users/2600hz/followers","following_url":"https://api.github.com/users/2600hz/following{/other_user}","gists_url":"https://api.github.com/users/2600hz/gists{/gist_id}","starred_url":"https://api.github.com/users/2600hz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/2600hz/subscriptions","organizations_url":"https://api.github.com/users/2600hz/orgs","repos_url":"https://api.github.com/users/2600hz/repos","events_url":"https://api.github.com/users/2600hz/events{/privacy}","received_events_url":"https://api.github.com/users/2600hz/received_events","type":"Organization","site_admin":false},"repo":{"id":2966241,"node_id":"MDEwOlJlcG9zaXRvcnkyOTY2MjQx","name":"kazoo","full_name":"2600hz/kazoo","owner":{"login":"2600hz","id":408801,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQwODgwMQ==","avatar_url":"https://avatars3.githubusercontent.com/u/408801?v=4","gravatar_id":"","url":"https://api.github.com/users/2600hz","html_url":"https://github.com/2600hz","followers_url":"https://api.github.com/users/2600hz/followers","following_url":"https://api.github.com/users/2600hz/following{/other_user}","gists_url":"https://api.github.com/users/2600hz/gists{/gist_id}","starred_url":"https://api.github.com/users/2600hz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/2600hz/subscriptions","organizations_url":"https://api.github.com/users/2600hz/orgs","repos_url":"https://api.github.com/users/2600hz/repos","events_url":"https://api.github.com/users/2600hz/events{/privacy}","received_events_url":"https://api.github.com/users/2600hz/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/2600hz/kazoo","description":"The core of an open-source, distributed, highly scalable platform designed to provide robust telecom services","fork":false,"url":"https://api.github.com/repos/2600hz/kazoo","forks_url":"https://api.github.com/repos/2600hz/kazoo/forks","keys_url":"https://api.github.com/repos/2600hz/kazoo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/2600hz/kazoo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/2600hz/kazoo/teams","hooks_url":"https://api.github.com/repos/2600hz/kazoo/hooks","issue_events_url":"https://api.github.com/repos/2600hz/kazoo/issues/events{/number}","events_url":"https://api.github.com/repos/2600hz/kazoo/events","assignees_url":"https://api.github.com/repos/2600hz/kazoo/assignees{/user}","branches_url":"https://api.github.com/repos/2600hz/kazoo/branches{/branch}","tags_url":"https://api.github.com/repos/2600hz/kazoo/tags","blobs_url":"https://api.github.com/repos/2600hz/kazoo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/2600hz/kazoo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/2600hz/kazoo/git/refs{/sha}","trees_url":"https://api.github.com/repos/2600hz/kazoo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/2600hz/kazoo/statuses/{sha}","languages_url":"https://api.github.com/repos/2600hz/kazoo/languages","stargazers_url":"https://api.github.com/repos/2600hz/kazoo/stargazers","contributors_url":"https://api.github.com/repos/2600hz/kazoo/contributors","subscribers_url":"https://api.github.com/repos/2600hz/kazoo/subscribers","subscription_url":"https://api.github.com/repos/2600hz/kazoo/subscription","commits_url":"https://api.github.com/repos/2600hz/kazoo/commits{/sha}","git_commits_url":"https://api.github.com/repos/2600hz/kazoo/git/commits{/sha}","comments_url":"https://api.github.com/repos/2600hz/kazoo/comments{/number}","issue_comment_url":"https://api.github.com/repos/2600hz/kazoo/issues/comments{/number}","contents_url":"https://api.github.com/repos/2600hz/kazoo/contents/{+path}","compare_url":"https://api.github.com/repos/2600hz/kazoo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/2600hz/kazoo/merges","archive_url":"https://api.github.com/repos/2600hz/kazoo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/2600hz/kazoo/downloads","issues_url":"https://api.github.com/repos/2600hz/kazoo/issues{/number}","pulls_url":"https://api.github.com/repos/2600hz/kazoo/pulls{/number}","milestones_url":"https://api.github.com/repos/2600hz/kazoo/milestones{/number}","notifications_url":"https://api.github.com/repos/2600hz/kazoo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/2600hz/kazoo/labels{/name}","releases_url":"https://api.github.com/repos/2600hz/kazoo/releases{/id}","deployments_url":"https://api.github.com/repos/2600hz/kazoo/deployments","created_at":"2011-12-12T18:08:02Z","updated_at":"2018-06-13T23:38:36Z","pushed_at":"2018-06-14T17:10:54Z","git_url":"git://github.com/2600hz/kazoo.git","ssh_url":"git@github.com:2600hz/kazoo.git","clone_url":"https://github.com/2600hz/kazoo.git","svn_url":"https://github.com/2600hz/kazoo","homepage":"http://www.2600hz.org/","size":370424,"stargazers_count":590,"watchers_count":590,"language":"Erlang","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":317,"mirror_url":null,"archived":false,"open_issues_count":28,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":317,"open_issues":28,"watchers":590,"default_branch":"master"}},"base":{"label":"2600hz:master","ref":"master","sha":"b870ca0d1fdb8c2aa06679f920ae468b041119de","user":{"login":"2600hz","id":408801,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQwODgwMQ==","avatar_url":"https://avatars3.githubusercontent.com/u/408801?v=4","gravatar_id":"","url":"https://api.github.com/users/2600hz","html_url":"https://github.com/2600hz","followers_url":"https://api.github.com/users/2600hz/followers","following_url":"https://api.github.com/users/2600hz/following{/other_user}","gists_url":"https://api.github.com/users/2600hz/gists{/gist_id}","starred_url":"https://api.github.com/users/2600hz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/2600hz/subscriptions","organizations_url":"https://api.github.com/users/2600hz/orgs","repos_url":"https://api.github.com/users/2600hz/repos","events_url":"https://api.github.com/users/2600hz/events{/privacy}","received_events_url":"https://api.github.com/users/2600hz/received_events","type":"Organization","site_admin":false},"repo":{"id":2966241,"node_id":"MDEwOlJlcG9zaXRvcnkyOTY2MjQx","name":"kazoo","full_name":"2600hz/kazoo","owner":{"login":"2600hz","id":408801,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQwODgwMQ==","avatar_url":"https://avatars3.githubusercontent.com/u/408801?v=4","gravatar_id":"","url":"https://api.github.com/users/2600hz","html_url":"https://github.com/2600hz","followers_url":"https://api.github.com/users/2600hz/followers","following_url":"https://api.github.com/users/2600hz/following{/other_user}","gists_url":"https://api.github.com/users/2600hz/gists{/gist_id}","starred_url":"https://api.github.com/users/2600hz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/2600hz/subscriptions","organizations_url":"https://api.github.com/users/2600hz/orgs","repos_url":"https://api.github.com/users/2600hz/repos","events_url":"https://api.github.com/users/2600hz/events{/privacy}","received_events_url":"https://api.github.com/users/2600hz/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/2600hz/kazoo","description":"The core of an open-source, distributed, highly scalable platform designed to provide robust telecom services","fork":false,"url":"https://api.github.com/repos/2600hz/kazoo","forks_url":"https://api.github.com/repos/2600hz/kazoo/forks","keys_url":"https://api.github.com/repos/2600hz/kazoo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/2600hz/kazoo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/2600hz/kazoo/teams","hooks_url":"https://api.github.com/repos/2600hz/kazoo/hooks","issue_events_url":"https://api.github.com/repos/2600hz/kazoo/issues/events{/number}","events_url":"https://api.github.com/repos/2600hz/kazoo/events","assignees_url":"https://api.github.com/repos/2600hz/kazoo/assignees{/user}","branches_url":"https://api.github.com/repos/2600hz/kazoo/branches{/branch}","tags_url":"https://api.github.com/repos/2600hz/kazoo/tags","blobs_url":"https://api.github.com/repos/2600hz/kazoo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/2600hz/kazoo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/2600hz/kazoo/git/refs{/sha}","trees_url":"https://api.github.com/repos/2600hz/kazoo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/2600hz/kazoo/statuses/{sha}","languages_url":"https://api.github.com/repos/2600hz/kazoo/languages","stargazers_url":"https://api.github.com/repos/2600hz/kazoo/stargazers","contributors_url":"https://api.github.com/repos/2600hz/kazoo/contributors","subscribers_url":"https://api.github.com/repos/2600hz/kazoo/subscribers","subscription_url":"https://api.github.com/repos/2600hz/kazoo/subscription","commits_url":"https://api.github.com/repos/2600hz/kazoo/commits{/sha}","git_commits_url":"https://api.github.com/repos/2600hz/kazoo/git/commits{/sha}","comments_url":"https://api.github.com/repos/2600hz/kazoo/comments{/number}","issue_comment_url":"https://api.github.com/repos/2600hz/kazoo/issues/comments{/number}","contents_url":"https://api.github.com/repos/2600hz/kazoo/contents/{+path}","compare_url":"https://api.github.com/repos/2600hz/kazoo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/2600hz/kazoo/merges","archive_url":"https://api.github.com/repos/2600hz/kazoo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/2600hz/kazoo/downloads","issues_url":"https://api.github.com/repos/2600hz/kazoo/issues{/number}","pulls_url":"https://api.github.com/repos/2600hz/kazoo/pulls{/number}","milestones_url":"https://api.github.com/repos/2600hz/kazoo/milestones{/number}","notifications_url":"https://api.github.com/repos/2600hz/kazoo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/2600hz/kazoo/labels{/name}","releases_url":"https://api.github.com/repos/2600hz/kazoo/releases{/id}","deployments_url":"https://api.github.com/repos/2600hz/kazoo/deployments","created_at":"2011-12-12T18:08:02Z","updated_at":"2018-06-13T23:38:36Z","pushed_at":"2018-06-14T17:10:54Z","git_url":"git://github.com/2600hz/kazoo.git","ssh_url":"git@github.com:2600hz/kazoo.git","clone_url":"https://github.com/2600hz/kazoo.git","svn_url":"https://github.com/2600hz/kazoo","homepage":"http://www.2600hz.org/","size":370424,"stargazers_count":590,"watchers_count":590,"language":"Erlang","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":317,"mirror_url":null,"archived":false,"open_issues_count":28,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":317,"open_issues":28,"watchers":590,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/2600hz/kazoo/pulls/4898"},"html":{"href":"https://github.com/2600hz/kazoo/pull/4898"},"issue":{"href":"https://api.github.com/repos/2600hz/kazoo/issues/4898"},"comments":{"href":"https://api.github.com/repos/2600hz/kazoo/issues/4898/comments"},"review_comments":{"href":"https://api.github.com/repos/2600hz/kazoo/pulls/4898/comments"},"review_comment":{"href":"https://api.github.com/repos/2600hz/kazoo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/2600hz/kazoo/pulls/4898/commits"},"statuses":{"href":"https://api.github.com/repos/2600hz/kazoo/statuses/f43df60020be206454414e4c361dd168944e9ed2"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"harenson"}}