Skip to content

Commit 3081c72

Browse files
authored
Merge pull request #526 from AmbireTech/sentry-benchmark
Sentry benchmark
2 parents 2ba6dcd + 28b386a commit 3081c72

File tree

16 files changed

+471
-86
lines changed

16 files changed

+471
-86
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
uses: sudo-bot/action-docker-compose@latest
6969
with:
7070
# https://docs.docker.com/compose/reference/overview/
71-
cli-args: "-f docker-compose.harness.yml up -d --build"
71+
cli-args: "-f docker-compose.harness.yml up -d --build adex-postgres adex-redis ganache-1 ganache-1337"
7272
- uses: actions-rs/toolchain@v1
7373
with:
7474
# No need to add `toolchain`, it will use `rust-toolchain` file instead

Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,3 @@ members = [
1010
"sentry",
1111
"test_harness",
1212
]
13-
14-
# [patch.crates-io]
15-
# postgres-types = { git = "https://github.com/elpiel/rust-postgres", branch = "boxed-dyn-ToSql"}

Dockerfile-sentry

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,21 @@ WORKDIR /usr/src/app
1010
RUN mkdir -p primitives/src/ adapter/src/ sentry/src/
1111

1212
COPY ./primitives/Cargo.toml ./primitives/Cargo.toml
13+
# we also need to copy the examples otherwise we will get error for them
14+
COPY ./primitives/examples ./primitives/examples
1315
RUN touch ./primitives/src/lib.rs && echo "pub fn main() {println!(\"cargo:rerun-if-changed=\\\"/tmp/build.rs\\\"\");}" >> ./primitives/src/lib.rs
1416

1517
COPY ./adapter/Cargo.toml ./adapter/Cargo.toml
1618
RUN touch ./adapter/src/lib.rs && echo "pub fn main() {println!(\"cargo:rerun-if-changed=\\\"/tmp/build.rs\\\"\");}" >> ./adapter/src/lib.rs
1719

1820
COPY ./sentry/Cargo.toml ./sentry/Cargo.toml
21+
COPY ./sentry/src/bin ./sentry/src/bin
1922
RUN touch ./sentry/src/main.rs && echo "fn main() {println!(\"cargo:rerun-if-changed=\\\"/tmp/build.rs\\\"\");}" >> ./sentry/src/main.rs
2023

2124
COPY ./Cargo.lock ./Cargo.lock
2225
RUN touch Cargo.toml && echo "[workspace]\n members = [ 'primitives', 'adapter', 'sentry' ]" >> Cargo.toml
2326

24-
RUN cargo build -p sentry --release
27+
RUN cargo build -p sentry --bin sentry --release
2528

2629
# remove the not needed build artifacts
2730
RUN rm -f target/release/deps/sentry*
@@ -35,7 +38,7 @@ COPY . .
3538
# We install the sentry binary with all features in Release mode
3639
# Include the full backtrace for easier debugging
3740

38-
RUN RUST_BACKTRACE=full cargo install --locked --path sentry --all-features
41+
RUN RUST_BACKTRACE=full cargo install --locked --path sentry --bin sentry --all-features
3942

4043
WORKDIR /usr/local/bin
4144

@@ -79,13 +82,11 @@ COPY docs/config/cloudflare_origin.crt /usr/local/share/ca-certificates/
7982

8083
RUN update-ca-certificates
8184

82-
RUN mkdir scripts
83-
84-
COPY ./scripts/sentry-docker ./scripts
85+
COPY ./scripts/sentry-docker ./scripts/sentry-docker
8586

8687
COPY --from=builder /usr/local/bin/sentry .
8788

88-
ENTRYPOINT ["./scripts/entrypoint.sh"]
89+
ENTRYPOINT ["./scripts/sentry-docker/entrypoint.sh"]
8990

9091
CMD sentry -a ${ADAPTER:-ethereum} \
9192
${KEYSTORE_FILE:+-k $KEYSTORE_FILE} \

docker-compose.ci.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.

docker-compose.harness.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,28 @@ services:
5858
networks:
5959
- adex-external
6060

61+
# Service used to bechmark the sentry application in release mode
62+
# It uses the dummy adapter and the Leader
63+
sentry-dummy-leader-release:
64+
restart: unless-stopped
65+
build:
66+
context: .
67+
dockerfile: Dockerfile-sentry
68+
container_name: adex-sentry-dummy-leader-release
69+
ports:
70+
- "8005:8005"
71+
environment:
72+
ENV: development
73+
IP_ADDR: 0.0.0.0
74+
PORT: 8005
75+
POSTGRES_DB: sentry_leader
76+
POSTGRES_HOST: adex-postgres
77+
REDIS_HOST: adex-redis
78+
ADAPTER: dummy
79+
DUMMY_IDENTITY: '0x80690751969B234697e9059e04ed72195c3507fa'
80+
REDIS_URL: redis://adex-redis:6379/0
81+
networks:
82+
- adex-external
83+
6184
networks:
6285
adex-external:

primitives/src/test_util.rs

Lines changed: 201 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use crate::{
1010
sentry::{CLICK, IMPRESSION},
1111
targeting::Rules,
1212
unified_num::FromWhole,
13-
AdUnit, Address, Campaign, Channel, EventSubmission, UnifiedNum, ValidatorDesc, ValidatorId,
14-
IPFS,
13+
AdUnit, Address, Campaign, ChainOf, Channel, EventSubmission, UnifiedNum, ValidatorDesc,
14+
ValidatorId, IPFS,
1515
};
1616

1717
pub use logger::discard_logger;
@@ -300,12 +300,203 @@ pub static DUMMY_IPFS: Lazy<[IPFS; 5]> = Lazy::new(|| {
300300
]
301301
});
302302

303-
#[cfg(test)]
304-
mod test {
305-
use super::*;
303+
/// List of test campaigns with keys `Campaign {Chain id} #{Number campaign}`
304+
pub static CAMPAIGNS: Lazy<[ChainOf<Campaign>; 3]> = Lazy::new(|| {
305+
let campaign_1337_1 = {
306+
let ganache_chain_info = GANACHE_CONFIG.chains["Ganache #1337"].clone();
307+
let token_info = ganache_chain_info.tokens["Mocked TOKEN 1337"].clone();
306308

307-
#[test]
308-
fn test_ids() {
309-
println!("{:?}", IDS[&LEADER]);
310-
}
311-
}
309+
let channel = Channel {
310+
leader: IDS[&LEADER],
311+
follower: IDS[&FOLLOWER],
312+
guardian: *GUARDIAN,
313+
token: token_info.address,
314+
nonce: 0_u64.into(),
315+
};
316+
317+
let leader_desc = ValidatorDesc {
318+
fee: UnifiedNum::from_whole(0.5),
319+
..DUMMY_VALIDATOR_LEADER.clone()
320+
};
321+
322+
let follower_desc = ValidatorDesc {
323+
fee: UnifiedNum::from_whole(0.4),
324+
..DUMMY_VALIDATOR_FOLLOWER.clone()
325+
};
326+
327+
let validators = Validators::new((leader_desc, follower_desc));
328+
329+
ChainOf::new(ganache_chain_info.chain, token_info).with_campaign(Campaign {
330+
id: "0x936da01f9abd4d9d80c702af85c822a8"
331+
.parse()
332+
.expect("Should parse"),
333+
channel,
334+
creator: *ADVERTISER,
335+
// 100 000
336+
budget: UnifiedNum::from_whole(100_000),
337+
validators,
338+
title: Some("Dummy Campaign".to_string()),
339+
pricing_bounds: vec![
340+
(
341+
IMPRESSION,
342+
Pricing {
343+
min: UnifiedNum::from_whole(0.0004),
344+
max: UnifiedNum::from_whole(0.0005),
345+
},
346+
),
347+
(
348+
CLICK,
349+
Pricing {
350+
min: UnifiedNum::from_whole(0.0006),
351+
max: UnifiedNum::from_whole(0.001),
352+
},
353+
),
354+
]
355+
.into_iter()
356+
.collect(),
357+
event_submission: Some(EventSubmission { allow: vec![] }),
358+
ad_units: vec![DUMMY_AD_UNITS[0].clone(), DUMMY_AD_UNITS[1].clone()],
359+
targeting_rules: Rules::new(),
360+
created: Utc.ymd(2021, 2, 1).and_hms(7, 0, 0),
361+
active: Active {
362+
from: Some(Utc.ymd(2022, 6, 27).and_hms(0, 0, 0)),
363+
to: Utc.ymd(2099, 1, 30).and_hms(0, 0, 0),
364+
},
365+
})
366+
};
367+
368+
let campaign_1337_2 = {
369+
let ganache_chain_info = GANACHE_CONFIG.chains["Ganache #1337"].clone();
370+
let token_info = ganache_chain_info.tokens["Mocked TOKEN 1337"].clone();
371+
372+
let channel = Channel {
373+
leader: IDS[&FOLLOWER],
374+
follower: IDS[&LEADER],
375+
guardian: *GUARDIAN_2,
376+
token: token_info.address,
377+
nonce: 0_u64.into(),
378+
};
379+
380+
let leader_desc = ValidatorDesc {
381+
fee: UnifiedNum::from_whole(0.1),
382+
..DUMMY_VALIDATOR_FOLLOWER.clone()
383+
};
384+
385+
let follower_desc = ValidatorDesc {
386+
fee: UnifiedNum::from_whole(0.05),
387+
..DUMMY_VALIDATOR_LEADER.clone()
388+
};
389+
let validators = Validators::new((leader_desc, follower_desc));
390+
391+
ChainOf::new(ganache_chain_info.chain, token_info).with_campaign(Campaign {
392+
id: "0x127b98248f4e4b73af409d10f62daeaa"
393+
.parse()
394+
.expect("Should parse"),
395+
channel,
396+
creator: *ADVERTISER,
397+
// 200 000
398+
budget: UnifiedNum::from_whole(200_000.0),
399+
validators,
400+
title: Some("Dummy Campaign 2 in Chain #1337".to_string()),
401+
pricing_bounds: vec![
402+
(
403+
IMPRESSION,
404+
Pricing {
405+
min: UnifiedNum::from_whole(0.0004),
406+
max: UnifiedNum::from_whole(0.0005),
407+
},
408+
),
409+
(
410+
CLICK,
411+
Pricing {
412+
min: UnifiedNum::from_whole(0.0006),
413+
max: UnifiedNum::from_whole(0.001),
414+
},
415+
),
416+
]
417+
.into_iter()
418+
.collect(),
419+
event_submission: Some(EventSubmission { allow: vec![] }),
420+
ad_units: vec![DUMMY_AD_UNITS[0].clone(), DUMMY_AD_UNITS[1].clone()],
421+
targeting_rules: Rules::new(),
422+
created: Utc.ymd(2021, 2, 1).and_hms(7, 0, 0),
423+
active: Active {
424+
from: None,
425+
to: Utc.ymd(2099, 1, 30).and_hms(0, 0, 0),
426+
},
427+
})
428+
};
429+
430+
let campaign_1_1 = {
431+
let ganache_chain_info = GANACHE_CONFIG.chains["Ganache #1"].clone();
432+
let token_info = ganache_chain_info.tokens["Mocked TOKEN 1"].clone();
433+
434+
let channel = Channel {
435+
leader: IDS[&LEADER],
436+
follower: IDS[&FOLLOWER],
437+
guardian: *GUARDIAN_2,
438+
token: token_info.address,
439+
nonce: 1_u64.into(),
440+
};
441+
442+
let leader_desc = ValidatorDesc {
443+
fee: UnifiedNum::from_whole(0.02),
444+
..DUMMY_VALIDATOR_LEADER.clone()
445+
};
446+
447+
let follower_desc = ValidatorDesc {
448+
fee: UnifiedNum::from_whole(0.0175),
449+
..DUMMY_VALIDATOR_FOLLOWER.clone()
450+
};
451+
452+
let validators = Validators::new((leader_desc, follower_desc));
453+
454+
ChainOf::new(ganache_chain_info.chain, token_info).with_campaign(Campaign {
455+
id: "0xa78f3492481b41a688488a7aa1ff17df"
456+
.parse()
457+
.expect("Should parse"),
458+
channel,
459+
creator: *ADVERTISER_2,
460+
// 20 000
461+
budget: UnifiedNum::from_whole(20_000),
462+
validators,
463+
title: Some("Dummy Campaign 3 in Chain #1".to_string()),
464+
pricing_bounds: vec![
465+
(
466+
IMPRESSION,
467+
Pricing {
468+
// 0.01500000
469+
// Per 1000 = 15.00000000
470+
min: UnifiedNum::from_whole(0.015),
471+
// 0.0250000
472+
// Per 1000 = 25.00000000
473+
max: UnifiedNum::from_whole(0.025),
474+
},
475+
),
476+
(
477+
CLICK,
478+
Pricing {
479+
// 0.03500000
480+
// Per 1000 = 35.00000000
481+
min: UnifiedNum::from_whole(0.035),
482+
// 0.06500000
483+
// Per 1000 = 65.00000000
484+
max: UnifiedNum::from_whole(0.065),
485+
},
486+
),
487+
]
488+
.into_iter()
489+
.collect(),
490+
event_submission: Some(EventSubmission { allow: vec![] }),
491+
ad_units: vec![DUMMY_AD_UNITS[2].clone(), DUMMY_AD_UNITS[3].clone()],
492+
targeting_rules: Rules::new(),
493+
created: Utc.ymd(2021, 2, 1).and_hms(7, 0, 0),
494+
active: Active {
495+
from: None,
496+
to: Utc.ymd(2099, 1, 30).and_hms(0, 0, 0),
497+
},
498+
})
499+
};
500+
501+
[campaign_1337_1, campaign_1337_2, campaign_1_1]
502+
});

scripts/sentry-docker/entrypoint.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ set -o errexit
44
set -o pipefail
55

66
>&2 echo "Waiting for redis..."
7-
REDIS_HOST=${REDIS_HOST:-redis}
7+
REDIS_HOST=${REDIS_HOST:-localhost}
88
REDIS_PORT=${REDIS_PORT:-6379}
9-
./scripts/wait-for-it.sh -h ${REDIS_HOST} -p ${REDIS_PORT} -t 10
9+
./scripts/sentry-docker/wait-for-it.sh -h ${REDIS_HOST} -p ${REDIS_PORT} -t 10
1010
>&2 echo "Redis is up - continuing..."
1111

1212
>&2 echo "Waiting for postgres..."
13-
POSTGRES_HOST=${POSTGRES_HOST:-postgres}
13+
POSTGRES_HOST=${POSTGRES_HOST:-localhost}
1414
POSTGRES_PORT=${POSTGRES_PORT:-5432}
15-
./scripts/wait-for-it.sh -h ${POSTGRES_HOST} -p ${POSTGRES_PORT} -t 10
15+
./scripts/sentry-docker/wait-for-it.sh -h ${POSTGRES_HOST} -p ${POSTGRES_PORT} -t 10
1616
>&2 echo "Postgres is up - continuing..."
1717

1818
exec "$@"

0 commit comments

Comments
 (0)