Skip to content

Instantly share code, notes, and snippets.

@sergey-chechaev
sergey-chechaev / building_basic_image.md
Last active May 16, 2022 15:47
Building a basic image
  1. Create directory and clone Browser Images
mkdir /opt/arm64 && cd /opt/arm64 
git clone https://github.com/aerokube/images
cd images/selenium/base
  1. Put Dockerfile.base to this directory. For building image, you need to set your hub.docker.com account and name for the image
@sergey-chechaev
sergey-chechaev / selenoid_m1_prepare.md
Last active May 16, 2022 16:07
Selenoid-m1 prepare environment

If you create this built on Silicon M1 you need to use flag platform linux/amd64

  1. Specify the environment variable
export DOCKER_CLI_EXPERIMENTAL=enabled
  1. Show buildx version information
docker buildx version

Готовый образ под M1 selenoid dumbdumbych/selenium_vnc_chrome_arm64:91.0.b

  1. Скачиваем рабочий образ под m1
docker pull dumbdumbych/selenium_vnc_chrome_arm64:91.0.b
  1. Создаем в папке config файл browsers.json со следующим содержимым
Benchmarking Preload with select...
Benchmarking Preload without select...
Memory usage statistics:
Name average deviation median 99th %
Preload with select 39.28 KB ±0.12% 39.30 KB 39.30 KB
Preload without select 89.21 KB ±0.09% 89.22 KB 89.23 KB
Comparison:
def list_user_posts_select(user_id) do
Post
|> where([p], p.user_id == ^user_id)
|> join(
:inner,
[post],
user in User,
on: user.id == post.user_id and is_nil(user.deleted_at) == true and
is_nil(user.blocked_at) == true
)
@sergey-chechaev
sergey-chechaev / post_photo_preload.ex
Created May 14, 2019 21:11
can't preload in one query
def list_user_posts(user_id) do
Post
|> where([p], p.user_id == ^user_id)
|> preload(post_photos: ^from(p in PostPhoto, order_by: p.position))
end
@sergey-chechaev
sergey-chechaev / best_binding_example.ex
Last active May 14, 2019 20:47
Best practice for use preload
def list_user_posts(user_id) do
Post
|> where([p], p.user_id == ^user_id)
|> join(
:inner,
[post],
user in User,
on: user.id == post.user_id and is_nil(user.deleted_at) == true and
is_nil(user.blocked_at) == true
)
@sergey-chechaev
sergey-chechaev / feed_benchmarking.ex
Last active May 14, 2019 16:21
benchmarking feed
Benchee.run(%{
"Preload 1 query sync" => fn -> one_query |> Repo.all(in_parallel: false) end,
"Preload 1 query async" => fn -> one_query |> Repo.all(in_parallel: true) end,
"Preload 5 query async" => fn -> five_query |> Repo.all(in_parallel: true) end,
"Preload 5 query sync" => fn -> five_query |> Repo.all(in_parallel: false) end
}, time: 10, memory_time: 2, warmup: 5)
Name ips average deviation median 99th %
Preload 5 query async 191.25 5.23 ms ±25.81% 4.96 ms 10.02 ms
def list_user_posts(user_id) do
Post
|> distinct(true)
|> where([p], p.user_id == ^user_id)
|> join(:left, [p], d in assoc(p, :user))
|> join(:left, [_p, d], co in assoc(d, :country))
|> join(:left, [_p, d], ci in assoc(d, :city))
|> join(:left, [p, _d], ph in assoc(p, :post_photos))
|> preload([_p, d, co, ci, ph], user: {d, country: co, city: ci}, post_photos: ph)
end
def list_user_posts(user_id) do
Post
|> where([p], p.user_id == ^user_id)
|> preload([:post_photos, user: [:country, :city]])
end