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 - 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 main user...")
60 Repo.one(from(u in User, order_by: fragment("RANDOM()"), limit: 1))
63 IO.puts("Fetching main user take #{to_sec(time)} sec.\n")
65 IO.puts("Fetching users...")
71 where: u.id != ^user.id,
72 order_by: fragment("RANDOM()"),
78 IO.puts("Fetching users take #{to_sec(time)} sec.\n")
80 generate_activities(user, users)
82 generate_dms(user, users, opts)
84 {:ok, activity} = generate_long_thread(user, users, opts)
86 generate_non_visible_message(user, users)
88 IO.puts("Users in DB: #{Repo.aggregate(from(u in User), :count, :id)}")
90 IO.puts("Activities in DB: #{Repo.aggregate(from(a in Pleroma.Activity), :count, :id)}")
92 IO.puts("Objects in DB: #{Repo.aggregate(from(o in Pleroma.Object), :count, :id)}")
95 "Notifications in DB: #{Repo.aggregate(from(n in Pleroma.Notification), :count, :id)}"
100 query_notifications(user)
102 query_long_thread(user, activity)
103 Pleroma.Config.put([:instance, :skip_thread_containment], false)
104 query_timelines(user)
108 IO.puts("Deleting old data...\n")
109 Ecto.Adapters.SQL.query!(Repo, "TRUNCATE users CASCADE;")
110 Ecto.Adapters.SQL.query!(Repo, "TRUNCATE activities CASCADE;")
111 Ecto.Adapters.SQL.query!(Repo, "TRUNCATE objects CASCADE;")