An HTTP Server, packaged with postgres, jaegar and perf-test module in a docker, to record ad deliveries, clicks and installs, and query the statistics.
Scala
as language
Http4s
as server
Postgres
as database
doobie
as jdbc layer for scala
circe
for json encoding and decoding
flywaydb
for database migrations
scala open tracing
for tracing context
jaegar
as the tracer
docker
- The application is dockerized along with postgres
and jaegar
scalacheck
- Generators are used to generate payload for perf-test
- Whenever an ad is loaded on a site, it is captured as a
delivery
. - User clicking on the ad is captured as a
click
. Click contains thedelivery_id
that lead to the click. - When the
click
leads to an install, it is captured asinstall
. Aninstall
contains theclick_id
that lead to the install. - Querying the stats is time based and/or category based (You can query stats grouped by
OS
andBrowser
) - Sample curls for every request is present in the
curls
directory - The project also contains a sub-project called
perf-test
which bombards the application server with requests (according to the parameters passed) - The
docker-compose.yml
has the application server, postgres, jaegar-all-in-one and the perf-test-app.
make setup_server
builds a fat jar out of the server (ads-stats).make setup_perf_test
builds a fat jar out of theperf-test
sub project.make run_server
packagespostgres
,jaegar
andads-stats-app
(server) into a docker container and expose127.0.0.1:8080
to the outside world.make perf_test_time_travel
runsads-stats-app
withno-op-tracer
and runs theperf-test
with the arguments supplied. Use this to pre-populate your database with data while without tracing it. Eg:make perf_test_time_travel deliveries=500 delivery_to_click_ratio=0.5 click_to_install_ratio=0.5
. This will insert500
deliveries, and clicks and installs will be inserted according to the ratio specified. Note that you will not be able to see any traces in thejaegar
dashboard after you run the test.make perf_test
runsads-stats
with a valid tracer and the traces will show up on thejaegar
dashboard. Eg:make perf_test delivery_to_click_ratio=0.5 click_to_install_ratio=0.5 delivery_to_query_ratio=0.25 running_time_in_seconds=50
. This will run the perf-test for 50 seconds and during this time the inserts will happen in the ratio specified.
You can see the traces by going to http://localhost:16686/
on your browser. Select ads-stats-app
service and then you can see the traced requests.
The ads-stats-app
server is started with the these properties
-Dcom.sun.management.jmxremote.rmi.port=9090 -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=9090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.local.only=false
This allows you to monitor the JVM from your localmachine, say using VisualVM. Open Visual VM -> Remote -> Add Remote Host. Here add the IP Address of ads-stats-app
. You can find the ip-address by running this command:
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container-id-of-ads-stats-app>
After adding the IP address, right click on the IP address and click Add JMX Connection
. A window similar to the one below should show up. Add the port 9090
to the IP address and click Ok (in my machine 172.17.0.4
happened to be the IP address of ads-stats-app
).
You should be able to monitor the app now.