Browse Source

Docker Perl tests (#3426)

* perl

* perl

* fix kelp mongo

* travis for perl tests

* fix web-simple
Nate 7 years ago
parent
commit
f9360fc33b

+ 5 - 5
.travis.yml

@@ -116,11 +116,11 @@ env:
     # - "TESTDIR=Lua/octopus"
     # - "TESTDIR=Lua/openresty"
      - "TESTDIR=Nim/jester"
-    # - "TESTDIR=Perl/dancer"
-    # - "TESTDIR=Perl/kelp"
-    # - "TESTDIR=Perl/mojolicious"
-    # - "TESTDIR=Perl/plack"
-    # - "TESTDIR=Perl/web-simple"
+     - "TESTDIR=Perl/dancer"
+     - "TESTDIR=Perl/kelp"
+     - "TESTDIR=Perl/mojolicious"
+     - "TESTDIR=Perl/plack"
+     - "TESTDIR=Perl/web-simple"
     # - "TESTDIR=PHP/cakephp"
     # - "TESTDIR=PHP/hhvm"
     # - "TESTDIR=PHP/php"

+ 0 - 2
frameworks/Perl/dancer/.gitignore

@@ -1,2 +0,0 @@
-/cpanfile.snapshot
-/local/

+ 0 - 1
frameworks/Perl/dancer/benchmark_config.json

@@ -2,7 +2,6 @@
   "framework": "dancer",
   "tests": [{
     "default": {
-      "setup_file": "setup-mysql",
       "json_url": "/json",
       "db_url": "/db",
       "query_url": "/db?queries=",

+ 28 - 0
frameworks/Perl/dancer/dancer.dockerfile

@@ -0,0 +1,28 @@
+FROM tfb/nginx:latest
+
+FROM tfb/perl:latest
+
+COPY --from=0 /nginx /nginx
+
+ENV NGINX_HOME="/nginx"
+ENV PATH=/nginx/sbin:${PATH}
+
+ADD ./ /dancer
+
+WORKDIR /dancer
+
+ENV PERL_CARTON_PATH=/dancer/local
+ENV PERL5LIB=${PERL_CARTON_PATH}/lib/perl5
+ENV PATH=${PERL_CARTON_PATH}/bin:${PERL_HOME}/bin:${PATH}
+
+RUN cpanm --notest --no-man-page \
+      [email protected] \
+      Dancer::Plugin::[email protected] \
+      [email protected] \
+      DBD::[email protected] \
+      JSON::[email protected] \
+      [email protected] \
+      [email protected]
+
+CMD nginx -c /dancer/nginx.conf && \
+    plackup -E production -s Starman --workers=${CPU_COUNT} -l /tmp/perl-dancer.sock -a ./app.pl

+ 5 - 11
frameworks/Perl/dancer/nginx.conf

@@ -1,13 +1,16 @@
-# Replaced by setup.py
+user root;
 error_log stderr error;
 
 worker_processes 2;
 
 events {
   worker_connections  1024;
+  multi_accept on;
 }
 
 http {
+  client_body_temp_path      /tmp;
+
   output_buffers   1 32k;
   postpone_output  1460;
 
@@ -18,22 +21,13 @@ http {
 
   tcp_nodelay      on;
 
-  upstream backendurl {
-    server unix:/tmp/perl-dancer.sock;
-  }
-
   server {
     listen 8080;
     server_name localhost;
 
     location / {
-      try_files $uri @proxy;
-      expires max;
+      proxy_pass http://unix:/tmp/perl-dancer.sock;
     }
 
-    location @proxy {
-      proxy_set_header Host $http_host;
-      proxy_pass http://backendurl;
-    }
   }
 }

+ 0 - 5
frameworks/Perl/dancer/setup-mysql.sh

@@ -1,5 +0,0 @@
-#!/bin/bash
-
-fw_depends mysql
-
-source ./setup.sh

+ 0 - 16
frameworks/Perl/dancer/setup.sh

@@ -1,16 +0,0 @@
-#!/bin/bash
-
-fw_depends perl nginx
-
-cpanm --notest --no-man-page \
-    [email protected] \
-    Dancer::Plugin::[email protected] \
-    [email protected] \
-    DBD::[email protected] \
-    JSON::[email protected] \
-    [email protected] \
-    [email protected]
-    
-nginx -c ${TROOT}/nginx.conf
-
-plackup -E production -s Starman --workers=${CPU_COUNT} -l /tmp/perl-dancer.sock -a ./app.pl &

+ 25 - 17
frameworks/Perl/kelp/app.pl

@@ -8,23 +8,31 @@ use utf8;
 
 module 'JSON::XS';
 
-my $mongo   = MongoDB::MongoClient->new( host => 'localhost', port => 27017 );
-my $mdb     = $mongo->get_database('hello_world');
-my $world   = $mdb->get_collection('world');
-my $fortune = $mdb->get_collection('fortune');
-
-my $dbh = DBI->connect(
-    "dbi:mysql:database=hello_world;host=localhost;port=3306",
-    'benchmarkdbuser',
-    'benchmarkdbpass',
-    { RaiseError => 0, PrintError => 0, mysql_enable_utf8 => 1 }
-);
-
-my @sth = map { $dbh->prepare($_) } (
-    "SELECT * FROM World WHERE id = ?",
-    "SELECT * FROM Fortune",
-    "UPDATE World SET randomNumber = ? WHERE id = ?",
-);
+my $mongo;
+my $mdb;
+my $world;
+my $fortune;
+my @sth;
+my $dbh;
+
+if ($ENV{MONGO}) {
+    $mongo   = MongoDB::MongoClient->new( host => 'TFB-database', port => 27017 );
+    $mdb     = $mongo->get_database('hello_world');
+    $world   = $mdb->get_collection('world');
+    $fortune = $mdb->get_collection('fortune');
+} else {
+    $dbh = DBI->connect(
+        "dbi:mysql:database=hello_world;host=TFB-database;port=3306",
+        'benchmarkdbuser',
+        'benchmarkdbpass',
+        { RaiseError => 0, PrintError => 0, mysql_enable_utf8 => 1 }
+    );
+    @sth = map { $dbh->prepare($_) } (
+        "SELECT * FROM World WHERE id = ?",
+        "SELECT * FROM Fortune",
+        "UPDATE World SET randomNumber = ? WHERE id = ?",
+    );
+}
 
 get '/json' => sub {
     { message => 'Hello, World!' };

+ 4 - 8
frameworks/Perl/kelp/benchmark_config.json

@@ -2,11 +2,9 @@
   "framework": "kelp",
   "tests": [{
     "default": {
-      "setup_file": "setup",
-      "json_url": "/json",
-      "db_url": "/db",
-      "query_url": "/queries?queries=",
-      "fortune_url": "/fortunes",
+      "db_url": "/db/mysql",
+      "query_url": "/queries/mysql?queries=",
+      "fortune_url": "/fortunes/mysql",
       "plaintext_url": "/plaintext",
       "port": 8080,
       "approach": "Realistic",
@@ -24,9 +22,7 @@
       "versus": ""
     },
     "mongodb": {
-      "setup_file": "setup",
-      "json_url": "/json",
-      "db_url": "/db",
+      "db_url": "/db/mongo",
       "query_url": "/queries/mongo?queries=",
       "fortune_url": "/fortunes/mongo",
       "plaintext_url": "/plaintext",

+ 28 - 0
frameworks/Perl/kelp/kelp-base.dockerfile

@@ -0,0 +1,28 @@
+FROM tfb/nginx:latest
+
+FROM tfb/perl:latest
+
+COPY --from=0 /nginx /nginx
+
+ENV NGINX_HOME="/nginx"
+ENV PATH=/nginx/sbin:${PATH}
+
+WORKDIR /kelp
+
+ENV PERL_CARTON_PATH=/kelp/local
+ENV PERL5LIB=${PERL_CARTON_PATH}/lib/perl5
+ENV PATH=${PERL_CARTON_PATH}/bin:${PERL_HOME}/bin:${PATH}
+
+RUN cpanm --notest --no-man-page \
+        [email protected] \
+        [email protected] \
+        DBD::[email protected] \
+        [email protected] \
+        Kelp::Module::JSON::[email protected] \
+        HTML::[email protected] \
+        HTTP::Parser::[email protected] \
+        [email protected]
+
+ADD ./app.ini /kelp/
+ADD ./app.pl /kelp/
+ADD ./nginx.conf /kelp/

+ 8 - 0
frameworks/Perl/kelp/kelp-mongodb.dockerfile

@@ -0,0 +1,8 @@
+FROM tfb/kelp-base:latest
+
+ENV MONGO=1
+
+RUN sleep 10
+
+CMD nginx -c /kelp/nginx.conf && \
+    plackup -E production -s Starman --workers=${CPU_COUNT} -l /tmp/perl-kelp.sock -a ./app.pl

+ 4 - 0
frameworks/Perl/kelp/kelp.dockerfile

@@ -0,0 +1,4 @@
+FROM tfb/kelp-base:latest
+
+CMD nginx -c /kelp/nginx.conf && \
+    plackup -E production -s Starman --workers=${CPU_COUNT} -l /tmp/perl-kelp.sock -a ./app.pl

+ 5 - 11
frameworks/Perl/kelp/nginx.conf

@@ -1,13 +1,16 @@
-# Replaced by setup.py
+user root;
 error_log stderr error;
 
 worker_processes 2;
 
 events {
   worker_connections  1024;
+  multi_accept on;
 }
 
 http {
+  client_body_temp_path      /tmp;
+
   output_buffers   1 32k;
   postpone_output  1460;
 
@@ -18,22 +21,13 @@ http {
 
   tcp_nodelay      on;
 
-  upstream backendurl {
-    server unix:/home/tfb/FrameworkBenchmarks/kelp/frameworks-benchmark.sock;
-  }
-
   server {
     listen 8080;
     server_name localhost;
 
     location / {
-      try_files $uri @proxy;
-      expires max;
+      proxy_pass http://unix:/tmp/perl-kelp.sock;
     }
 
-    location @proxy {
-      proxy_set_header Host $http_host;
-      proxy_pass http://backendurl;
-    }
   }
 }

+ 0 - 21
frameworks/Perl/kelp/setup.sh

@@ -1,21 +0,0 @@
-#!/bin/bash
-
-sed -i 's|localhost|'"${DBHOST}"'|g' app.pl
-sed -i 's|user .*;|user '"$(id -u -n)"';|g' nginx.conf
-sed -i 's|server unix.*frameworks-benchmark.sock;|server unix:'"${TROOT}"'/frameworks-benchmark.sock;|g' nginx.conf
-
-fw_depends perl nginx mysql mongodb
-
-cpanm --notest --no-man-page \
-    [email protected] \
-    [email protected] \
-    DBD::[email protected] \
-    [email protected] \
-    Kelp::Module::JSON::[email protected] \
-    HTML::[email protected] \
-    HTTP::Parser::[email protected] \
-    [email protected]
-
-nginx -c ${TROOT}/nginx.conf
-
-plackup -E production -s Starman --workers=${CPU_COUNT} -l ${TROOT}/frameworks-benchmark.sock -a ./app.pl &

+ 0 - 2
frameworks/Perl/mojolicious/.gitignore

@@ -1,2 +0,0 @@
-local
-*.pid

+ 17 - 0
frameworks/Perl/mojolicious/mojolicious.dockerfile

@@ -0,0 +1,17 @@
+FROM tfb/perl:latest
+
+WORKDIR /mojo
+
+ENV PERL_CARTON_PATH=/kelp/local
+ENV PERL5LIB=${PERL_CARTON_PATH}/lib/perl5
+ENV PATH=${PERL_CARTON_PATH}/bin:${PERL_HOME}/bin:${PATH}
+
+ADD ./cpanfile* ./
+
+RUN carton install --cpanfile /mojo/cpanfile
+
+ENV  LIBEV_FLAGS=7
+
+ADD ./app.pl ./
+
+CMD hypnotoad -f /mojo/app.pl

+ 0 - 10
frameworks/Perl/mojolicious/setup.sh

@@ -1,10 +0,0 @@
-#!/bin/bash
-
-fw_depends postgresql perl
-
-carton install --cpanfile ${TROOT}/cpanfile
-
-export LIBEV_FLAGS=7
-HYPNOTOAD=$(${PERL_HOME}/bin/carton exec which hypnotoad)
-
-carton exec perl ${HYPNOTOAD} ${TROOT}/app.pl

+ 1 - 1
frameworks/Perl/plack/app.psgi

@@ -5,7 +5,7 @@ use JSON::XS qw(encode_json);
 use DBI;
 
 my $dbh = DBI->connect_cached(
-    'dbi:mysql:database=hello_world;host=localhost;port=3306', 
+    'dbi:mysql:database=hello_world;host=TFB-database;port=3306',
     'benchmarkdbuser',
     'benchmarkdbpass',
     { AutoInactiveDestroy => 1, mysql_enable_utf8 => 1 }

+ 0 - 1
frameworks/Perl/plack/benchmark_config.json

@@ -2,7 +2,6 @@
   "framework": "plack",
   "tests": [{
     "default": {
-      "setup_file": "setup",
       "json_url": "/json",
       "db_url": "/db",
       "port": 8080,

+ 16 - 15
frameworks/Perl/plack/nginx.conf

@@ -1,32 +1,33 @@
-# Replaced by setup.py
+user root;
 error_log stderr error;
-pid        /tmp/nginx.pid;
-worker_processes 4;
+
+worker_processes 2;
 
 events {
-  worker_connections  4096;
+  worker_connections  1024;
   multi_accept on;
 }
 
 http {
+  client_body_temp_path      /tmp;
+
+  output_buffers   1 32k;
+  postpone_output  1460;
+
   access_log       off;
-  tcp_nodelay      on;
-  keepalive_requests 50000;
-  etag off;
 
-  upstream backendurl {
-    server unix:/home/tfb/FrameworkBenchmarks/plack/app.sock;
-    keepalive 8;
-  }
+  sendfile         on;
+  tcp_nopush       on;
+
+  tcp_nodelay      on;
 
   server {
     listen 8080;
     server_name localhost;
+
     location / {
-      proxy_http_version 1.1;
-      proxy_set_header Connection "";
-      proxy_pass http://backendurl;
+      proxy_pass http://unix:/tmp/perl-plack.sock;
     }
+
   }
 }
-

+ 31 - 0
frameworks/Perl/plack/plack.dockerfile

@@ -0,0 +1,31 @@
+FROM tfb/nginx:latest
+
+FROM tfb/perl:latest
+
+COPY --from=0 /nginx /nginx
+
+ENV NGINX_HOME="/nginx"
+ENV PATH=/nginx/sbin:${PATH}
+
+WORKDIR /plack
+
+ENV PERL_CARTON_PATH=/plack/local
+ENV PERL5LIB=${PERL_CARTON_PATH}/lib/perl5
+ENV PATH=${PERL_CARTON_PATH}/bin:${PERL_HOME}/bin:${PATH}
+
+RUN cpanm --notest --no-man-page \
+        JSON::[email protected] \
+        HTTP::Parser::[email protected] \
+        [email protected] \
+        [email protected] \
+        DBD::[email protected] \
+        [email protected]
+
+ADD ./app.pid /plack/
+ADD ./app.psgi /plack/
+add ./nginx.conf /plack/
+
+CMD nginx -c /plack/nginx.conf && \
+    start_server --backlog=16384 --pid-file=/plack/app.pid --path=/tmp/perl-plack.sock -- plackup \
+    -E production -s Starlet --max-keepalive-reqs 1000 --max-reqs-per-child 50000 \
+    --min-reqs-per-child 40000 --max-workers=${CPU_COUNT} -a /plack/app.psgi

+ 0 - 17
frameworks/Perl/plack/setup.sh

@@ -1,17 +0,0 @@
-#!/bin/bash
-
-sed -i 's|localhost|'"${DBHOST}"'|g' app.psgi
-sed -i 's|server unix:.*/FrameworkBenchmarks/plack|server unix:'"${TROOT}"'|g' nginx.conf
-
-fw_depends mysql perl nginx
-
-cpanm --notest --no-man-page \
-    JSON::[email protected] \
-    HTTP::Parser::[email protected] \
-    [email protected] \
-    [email protected] \
-    DBD::[email protected] \
-    [email protected]
-    
-nginx -c $TROOT/nginx.conf
-start_server --backlog=16384 --pid-file=$TROOT/app.pid --path=$TROOT/app.sock -- plackup -E production -s Starlet --max-keepalive-reqs 1000 --max-reqs-per-child 50000 --min-reqs-per-child 40000 --max-workers=${CPU_COUNT} -a $TROOT/app.psgi &

+ 0 - 1
frameworks/Perl/web-simple/benchmark_config.json

@@ -2,7 +2,6 @@
   "framework": "web-simple",
   "tests": [{
     "default": {
-      "setup_file": "setup-mysql",
       "json_url": "/json",
       "db_url": "/db",
       "query_url": "/query?queries=",

+ 5 - 12
frameworks/Perl/web-simple/nginx.conf

@@ -1,14 +1,16 @@
-# Replaced by setup.py
-user USR;
+user root;
 error_log stderr error;
 
 worker_processes 2;
 
 events {
   worker_connections  1024;
+  multi_accept on;
 }
 
 http {
+  client_body_temp_path      /tmp;
+
   output_buffers   1 32k;
   postpone_output  1460;
 
@@ -19,22 +21,13 @@ http {
 
   tcp_nodelay      on;
 
-  upstream backendurl {
-    server unix:/home/tfb/FrameworkBenchmarks/web-simple/frameworks-benchmark.sock;
-  }
-
   server {
     listen 8080;
     server_name localhost;
 
     location / {
-      try_files $uri @proxy;
-      expires max;
+      proxy_pass http://unix:/tmp/perl-simple.sock;
     }
 
-    location @proxy {
-      proxy_set_header Host $http_host;
-      proxy_pass http://backendurl;
-    }
   }
 }

+ 0 - 5
frameworks/Perl/web-simple/setup-mysql.sh

@@ -1,5 +0,0 @@
-#!/bin/bash
-
-fw_depends mysql
-
-source ./setup.sh

+ 0 - 17
frameworks/Perl/web-simple/setup.sh

@@ -1,17 +0,0 @@
-#!/bin/bash
-
-sed -i 's|server unix:.*/FrameworkBenchmarks/web-simple|server unix:'"${TROOT}"'|g' nginx.conf
-
-fw_depends perl nginx
-
-cpanm --notest --no-man-page  \
-    Web::[email protected] \
-    [email protected] \
-    DBD::[email protected] \
-    [email protected] \
-    [email protected] \
-    JSON::[email protected]
-    
-nginx -c $TROOT/nginx.conf
-
-plackup -E production -s Starman --workers=${CPU_COUNT} -l $TROOT/frameworks-benchmark.sock -a $TROOT/app.pl &

+ 30 - 0
frameworks/Perl/web-simple/web-simple.dockerfile

@@ -0,0 +1,30 @@
+FROM tfb/nginx:latest
+
+FROM tfb/perl:latest
+
+COPY --from=0 /nginx /nginx
+
+ENV NGINX_HOME="/nginx"
+ENV PATH=/nginx/sbin:${PATH}
+
+WORKDIR /simple
+
+ENV PERL_CARTON_PATH=/simple/local
+ENV PERL5LIB=${PERL_CARTON_PATH}/lib/perl5
+ENV PATH=${PERL_CARTON_PATH}/bin:${PERL_HOME}/bin:${PATH}
+
+RUN cpanm --notest --no-man-page  \
+        Web::[email protected] \
+        [email protected] \
+        DBD::[email protected] \
+        [email protected] \
+        [email protected] \
+        JSON::[email protected]
+
+ADD ./conf /simple/
+ADD ./app.pl /simple/
+ADD ./nginx.conf /simple/
+
+CMD nginx -c /simple/nginx.conf && \
+    plackup -E production -s Starman --workers=${CPU_COUNT} \
+    -l /tmp/perl-simple.sock -a /simple/app.pl

+ 20 - 0
toolset/setup/docker/languages/perl.dockerfile

@@ -0,0 +1,20 @@
+FROM tfb/base:latest
+
+ENV PERL_VERSION="5.18"
+ENV PERL=/perl-${PERL_VERSION}
+
+RUN wget -q -O perl-build.pl https://raw.github.com/tokuhirom/Perl-Build/master/perl-build
+# compile with optimizations, n.b. this does not turn on debugging
+RUN perl perl-build.pl -DDEBUGGING=-g 5.18.2 perl-${PERL_VERSION} 2>&1 | tee /perl-install.log | awk '{ if (NR%100 == 0) printf "."}'
+
+RUN wget -O cpanminus.pl http://cpanmin.us
+RUN perl-${PERL_VERSION}/bin/perl cpanminus.pl --notest --no-man-page App::cpanminus
+# Install only a bare-bones of Perl modules
+# Install others in the per-framework install script or cpanfile
+RUN perl-${PERL_VERSION}/bin/cpanm -f --notest --no-man-page Carton JSON JSON::XS IO::Socket::IP IO::Socket::SSL
+
+ENV PERL_HOME=${PERL}
+
+#ENV PERL_CARTON_PATH=$TROOT/local
+#ENV PERL5LIB=${PERL_CARTON_PATH}/lib/perl5
+#ENV PATH=${PERL_CARTON_PATH}/bin:${PERL_HOME}/bin:${PATH}

+ 0 - 23
toolset/setup/linux/languages/perl.sh

@@ -1,23 +0,0 @@
-#!/bin/bash
-
-fw_installed perl && return 0
-
-VERSION="5.18"
-PERL=$IROOT/perl-$VERSION
-
-fw_get -o perl-build.pl https://raw.github.com/tokuhirom/Perl-Build/master/perl-build
-# compile with optimizations, n.b. this does not turn on debugging
-perl perl-build.pl -DDEBUGGING=-g 5.18.2 perl-$VERSION 2>&1 | tee $IROOT/perl-install.log | awk '{ if (NR%100 == 0) printf "."}'
-
-fw_get -o cpanminus.pl http://cpanmin.us
-perl-$VERSION/bin/perl cpanminus.pl --notest --no-man-page App::cpanminus
-# Install only a bare-bones of Perl modules
-# Install others in the per-framework install script or cpanfile
-perl-$VERSION/bin/cpanm -f --notest --no-man-page Carton JSON JSON::XS IO::Socket::IP IO::Socket::SSL
-
-echo "export PERL_HOME=${PERL}" > $IROOT/perl.installed
-echo -e "export PERL_CARTON_PATH=\$TROOT/local" >> $IROOT/perl.installed
-echo -e "export PERL5LIB=\$PERL_CARTON_PATH/lib/perl5" >> $IROOT/perl.installed
-echo -e "export PATH=\$PERL_CARTON_PATH/bin:\$PERL_HOME/bin:\$PATH" >> $IROOT/perl.installed
-
-source $IROOT/perl.installed