1 defmodule Mix.Tasks.Pleroma.LoadTesting do
3 use Pleroma.LoadTesting.Helper
5 import Pleroma.LoadTesting.Generator
6 import Pleroma.LoadTesting.Fetcher
8 @shortdoc "Factory for generation data"
12 - local/remote activities with notifications
18 MIX_ENV=benchmark mix pleroma.load_testing --users 20000 --dms 20000 --thread_length 2000
19 MIX_ENV=benchmark mix pleroma.load_testing -u 20000 -d 20000 -t 2000
22 - `--users NUMBER` - number of users to generate. Defaults to: 20000. Alias: `-u`
23 - `--dms NUMBER` - number of direct messages to generate. Defaults to: 20000. Alias `-d`
24 - `--thread_length` - number of messages in thread. Defaults to: 2000. ALias `-t`
27 @aliases [u: :users, d: :dms, t: :thread_length]
31 thread_length: :integer
35 @thread_length_default 2_000
39 Pleroma.Config.put([:instance, :skip_thread_containment], true)
40 {opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases)
42 users_max = Keyword.get(opts, :users, @users_default)
43 dms_max = Keyword.get(opts, :dms, @dms_default)
44 thread_length = Keyword.get(opts, :thread_length, @thread_length_default)
49 Keyword.put(opts, :users_max, users_max)
50 |> Keyword.put(:dms_max, dms_max)
51 |> Keyword.put(:thread_length, thread_length)
55 # main user for queries
56 IO.puts("Fetching local main user...")
61 from(u in User, where: u.local == true, order_by: fragment("RANDOM()"), limit: 1)
65 IO.puts("Fetching main user take #{to_sec(time)} sec.\n")
67 IO.puts("Fetching local users...")
73 where: u.id != ^user.id,
74 where: u.local == true,
75 order_by: fragment("RANDOM()"),
81 IO.puts("Fetching local users take #{to_sec(time)} sec.\n")
83 IO.puts("Fetching remote users...")
85 {time, remote_users} =
89 where: u.id != ^user.id,
90 where: u.local == false,
91 order_by: fragment("RANDOM()"),
97 IO.puts("Fetching remote users take #{to_sec(time)} sec.\n")
99 generate_activities(user, users)
101 generate_remote_activities(user, remote_users)
103 generate_dms(user, users, opts)
105 {:ok, activity} = generate_long_thread(user, users, opts)
107 generate_non_visible_message(user, users)
109 IO.puts("Users in DB: #{Repo.aggregate(from(u in User), :count, :id)}")
111 IO.puts("Activities in DB: #{Repo.aggregate(from(a in Pleroma.Activity), :count, :id)}")
113 IO.puts("Objects in DB: #{Repo.aggregate(from(o in Pleroma.Object), :count, :id)}")
116 "Notifications in DB: #{Repo.aggregate(from(n in Pleroma.Notification), :count, :id)}"
120 query_timelines(user)
121 query_notifications(user)
123 query_long_thread(user, activity)
124 Pleroma.Config.put([:instance, :skip_thread_containment], false)
125 query_timelines(user)
129 IO.puts("Deleting old data...\n")
130 Ecto.Adapters.SQL.query!(Repo, "TRUNCATE users CASCADE;")
131 Ecto.Adapters.SQL.query!(Repo, "TRUNCATE activities CASCADE;")
132 Ecto.Adapters.SQL.query!(Repo, "TRUNCATE objects CASCADE;")