Skip to content
This repository has been archived by the owner on Apr 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1223 from europeana/release/v3.6.0
Browse files Browse the repository at this point in the history
Release v3.6.0
  • Loading branch information
rwd committed Feb 14, 2019
2 parents 797c279 + 00027db commit ba39e7e
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Expand Up @@ -20,7 +20,7 @@ GIT

GIT
remote: https://github.com/europeana/europeana-styleguide-ruby.git
revision: bea78676ad4d52e579a23908ea4a42e4df1141e9
revision: b7d9fc5b25ca5c4fb0db22ee6b316b4572d86cee
branch: develop
specs:
europeana-styleguide (0.3.0)
Expand Down
16 changes: 15 additions & 1 deletion README.md
Expand Up @@ -24,7 +24,8 @@ Europeana Portal with Collections as a Rails +

1. Install the gem bundle: `bundle install`
2. Generate Docker configuration files: `bundle exec bin/portal dockerize development`
You will be prompted to enter your Europeana API key.
You will be prompted to enter your Europeana API key. For another environment
than `development`, e.g. `profiling`, use its name in this command.
3. Bring it up: `docker-compose up`
4. Setup the database: `bundle exec rake db:setup`
5. Start the app: `bundle exec foreman start`
Expand Down Expand Up @@ -64,6 +65,19 @@ tests.

The integration tests use Firefox in headless mode.

### Benchmarking

A script is included to run various benchmarks from
[derailed_benchmarks](https://github.com/schneems/derailed_benchmarks):
* Size of bundled gems in production environment
* Memory allocation and IPS of search results and record pages

First ensure that you have initialised a `profiling` environment, and have
services running, e.g. by following the "Quick Start with Docker" instructions
above.

Run benchmarks with: `bin/benchmark`

### File storage

Files are stored using Paperclip. To configure it, create config/paperclip.yml
Expand Down
71 changes: 71 additions & 0 deletions bin/benchmark
@@ -0,0 +1,71 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

# Benchmark script using derailed_benchmarks and a fake API.

require_relative '../config/boot'
require 'colorize'
require 'open3'

def bm_common_env
'RAILS_ENV=profiling SKIP_FILE_WRITE=1 EUROPEANA_API_URL=http://localhost:3014/api'
end

def bm_gems
puts 'Bundled gems'.bold
puts
stdout, _stderr, _status = Open3.capture3('bundle exec derailed bundle:mem')
puts stdout.split("\n").first.sub('TOP: ', '')
puts
end

def bm_objects(name, path)
puts "#{name}: Objects".bold
puts
cmd = %(#{bm_common_env} TEST_COUNT=10 PATH_TO_HIT="#{path}" bundle exec derailed exec perf:objects)
stdout, stderr, status = Open3.capture3(cmd)
fail "Unable to benchmark objects\n#{stderr}" unless status.success?
puts stdout.split("\n")[0..4].join("\n")
puts
end

def bm_ips(name, path)
puts "#{name}: IPS".bold
puts
cmd = %(#{bm_common_env} TEST_COUNT=1_000 PATH_TO_HIT="#{path}" bundle exec derailed exec perf:ips)
stdout, stderr, status = Open3.capture3(cmd)
fail "Unable to benchmark IPS\n#{stderr}" unless status.success?
puts stdout
puts
end

def bm_path(name, path)
bm_objects(name, path)
bm_ips(name, path)
end

def fake_api_dir
@fake_api_dir ||= File.expand_path('../spec/support/fake_api', __dir__)
end

def start_fake_api
_stdout, stderr, status = Open3.capture3("docker-compose -f #{fake_api_dir}/docker-compose.yml up -d")
fail "Unable to start Docker fake API\n#{stderr}" unless status.success?
end

def stop_fake_api
_stdout, stderr, status = Open3.capture3("docker-compose -f #{fake_api_dir}/docker-compose.yml down")
fail "Unable to stop Docker fake API\n#{stderr}" unless status.success?
end

def with_fake_api
start_fake_api
yield
stop_fake_api
end

with_fake_api do
bm_gems
bm_path('Search results page', '/en/search?q=')
bm_path('Record page', '/en/record/123/abc.html')
end
12 changes: 12 additions & 0 deletions spec/support/fake_api/conf.d/default.conf
@@ -0,0 +1,12 @@
server {
listen 80;
server_name localhost;

rewrite ^/api/v2/record/ /record.json last;
rewrite ^/api/v2/search.json /search.json last;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}
1 change: 1 addition & 0 deletions spec/support/fake_api/data/record.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions spec/support/fake_api/data/search.json

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions spec/support/fake_api/docker-compose.yml
@@ -0,0 +1,9 @@
version: "3"
services:
nginx:
image: nginx
ports:
- "3014:80"
volumes:
- ./data:/usr/share/nginx/html
- ./conf.d:/etc/nginx/conf.d

0 comments on commit ba39e7e

Please sign in to comment.