2019-08-02 20:33:12 +02:00
|
|
|
defmodule Mix.Tasks.Pleroma.LoadTesting do
|
|
|
|
use Mix.Task
|
2020-01-14 12:42:30 +01:00
|
|
|
import Ecto.Query
|
2020-02-18 10:19:10 +01:00
|
|
|
import Pleroma.LoadTesting.Helper, only: [clean_tables: 0]
|
2020-01-14 12:42:30 +01:00
|
|
|
|
|
|
|
alias Pleroma.Repo
|
|
|
|
alias Pleroma.User
|
2019-08-02 20:33:12 +02:00
|
|
|
|
|
|
|
@shortdoc "Factory for generation data"
|
|
|
|
@moduledoc """
|
|
|
|
Generates data like:
|
2019-09-19 13:02:27 +02:00
|
|
|
- local/remote users
|
2020-01-14 12:42:30 +01: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 20:33:12 +02:00
|
|
|
|
|
|
|
## Generate data
|
2020-01-14 12:42:30 +01: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 20:33:12 +02:00
|
|
|
|
|
|
|
Options:
|
2019-09-06 15:37:18 +02:00
|
|
|
- `--users NUMBER` - number of users to generate. Defaults to: 20000. Alias: `-u`
|
2020-01-14 12:42:30 +01: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 20:33:12 +02:00
|
|
|
"""
|
|
|
|
|
2020-01-14 12:42:30 +01:00
|
|
|
@aliases [u: :users, f: :friends, i: :iterations, fu: :friends_used, nfu: :non_friends_used]
|
2019-09-04 19:18:11 +02:00
|
|
|
@switches [
|
|
|
|
users: :integer,
|
2020-01-14 12:42:30 +01:00
|
|
|
friends: :integer,
|
|
|
|
iterations: :integer,
|
|
|
|
friends_used: :integer,
|
|
|
|
non_friends_used: :integer
|
2019-09-04 19:18:11 +02:00
|
|
|
]
|
2019-08-02 20:33:12 +02:00
|
|
|
|
|
|
|
def run(args) do
|
2020-04-24 18:25:26 +02:00
|
|
|
Logger.configure(level: :error)
|
2020-01-14 12:42:30 +01:00
|
|
|
Mix.Pleroma.start_pleroma()
|
2019-09-04 19:18:11 +02:00
|
|
|
clean_tables()
|
2020-01-14 12:42:30 +01:00
|
|
|
{opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases)
|
2019-08-02 20:33:12 +02:00
|
|
|
|
2020-01-14 12:42:30 +01:00
|
|
|
user = Pleroma.LoadTesting.Users.generate(opts)
|
|
|
|
Pleroma.LoadTesting.Activities.generate(user, opts)
|
2019-09-04 19:18:11 +02:00
|
|
|
|
2019-09-05 15:01:52 +02:00
|
|
|
IO.puts("Users in DB: #{Repo.aggregate(from(u in User), :count, :id)}")
|
2019-08-02 20:33:12 +02:00
|
|
|
|
2019-09-05 15:01:52 +02:00
|
|
|
IO.puts("Activities in DB: #{Repo.aggregate(from(a in Pleroma.Activity), :count, :id)}")
|
2019-08-02 20:33:12 +02:00
|
|
|
|
2019-09-05 15:01:52 +02: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 20:33:12 +02:00
|
|
|
|
2020-01-14 12:42:30 +01:00
|
|
|
Pleroma.LoadTesting.Fetcher.run_benchmarks(user)
|
2019-08-02 20:33:12 +02:00
|
|
|
end
|
|
|
|
end
|