honkoma/benchmarks/mix/tasks/pleroma/load_testing.ex

75 lines
2.5 KiB
Elixir
Raw Normal View History

2019-08-02 18:33:12 +00:00
defmodule Mix.Tasks.Pleroma.LoadTesting do
use Mix.Task
2020-01-14 11:42:30 +00:00
import Ecto.Query
alias Ecto.Adapters.SQL
alias Pleroma.Repo
alias Pleroma.User
2019-08-02 18:33:12 +00:00
@shortdoc "Factory for generation data"
@moduledoc """
Generates data like:
2019-09-19 11:02:27 +00:00
- local/remote users
2020-01-14 11:42:30 +00:00
- local/remote activities with differrent visibility:
- simple activiities
- with emoji
- with mentions
- hellthreads
- with attachments
- with tags
- likes
- reblogs
- simple threads
- long threads
2019-08-02 18:33:12 +00:00
## Generate data
2020-01-14 11:42:30 +00:00
MIX_ENV=benchmark mix pleroma.load_testing --users 20000 --friends 1000 --iterations 170 --friends_used 20 --non_friends_used 20
MIX_ENV=benchmark mix pleroma.load_testing -u 20000 -f 1000 -i 170 -fu 20 -nfu 20
2019-08-02 18:33:12 +00:00
Options:
2019-09-06 13:37:18 +00:00
- `--users NUMBER` - number of users to generate. Defaults to: 20000. Alias: `-u`
2020-01-14 11:42:30 +00:00
- `--friends NUMBER` - number of friends for main user. Defaults to: 1000. Alias: `-f`
- `--iterations NUMBER` - number of iterations to generate activities. For each iteration in database is inserted about 120+ activities with different visibility, actors and types.Defaults to: 170. Alias: `-i`
- `--friends_used NUMBER` - number of main user friends used in activity generation. Defaults to: 20. Alias: `-fu`
- `--non_friends_used NUMBER` - number of non friends used in activity generation. Defaults to: 20. Alias: `-nfu`
2019-08-02 18:33:12 +00:00
"""
2020-01-14 11:42:30 +00:00
@aliases [u: :users, f: :friends, i: :iterations, fu: :friends_used, nfu: :non_friends_used]
2019-09-04 17:18:11 +00:00
@switches [
users: :integer,
2020-01-14 11:42:30 +00:00
friends: :integer,
iterations: :integer,
friends_used: :integer,
non_friends_used: :integer
2019-09-04 17:18:11 +00:00
]
2019-08-02 18:33:12 +00:00
def run(args) do
2020-01-14 11:42:30 +00:00
Mix.Pleroma.start_pleroma()
2019-09-04 17:18:11 +00:00
clean_tables()
2020-01-14 11:42:30 +00:00
{opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases)
2019-08-02 18:33:12 +00:00
2020-01-14 11:42:30 +00:00
user = Pleroma.LoadTesting.Users.generate(opts)
Pleroma.LoadTesting.Activities.generate(user, opts)
2019-09-04 17:18:11 +00:00
2019-09-05 13:01:52 +00:00
IO.puts("Users in DB: #{Repo.aggregate(from(u in User), :count, :id)}")
2019-08-02 18:33:12 +00:00
2019-09-05 13:01:52 +00:00
IO.puts("Activities in DB: #{Repo.aggregate(from(a in Pleroma.Activity), :count, :id)}")
2019-08-02 18:33:12 +00:00
2019-09-05 13:01:52 +00:00
IO.puts("Objects in DB: #{Repo.aggregate(from(o in Pleroma.Object), :count, :id)}")
IO.puts(
"Notifications in DB: #{Repo.aggregate(from(n in Pleroma.Notification), :count, :id)}"
)
2019-08-02 18:33:12 +00:00
2020-01-14 11:42:30 +00:00
Pleroma.LoadTesting.Fetcher.run_benchmarks(user)
2019-08-02 18:33:12 +00:00
end
defp clean_tables do
2019-09-06 13:37:18 +00:00
IO.puts("Deleting old data...\n")
2020-01-14 11:42:30 +00:00
SQL.query!(Repo, "TRUNCATE users CASCADE;")
SQL.query!(Repo, "TRUNCATE activities CASCADE;")
SQL.query!(Repo, "TRUNCATE objects CASCADE;")
SQL.query!(Repo, "TRUNCATE oban_jobs CASCADE;")
2019-08-02 18:33:12 +00:00
end
end