line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
518
|
use 5.008; |
|
1
|
|
|
|
|
2
|
|
2
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
16
|
|
3
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
53
|
|
4
|
|
|
|
|
|
|
package BenchmarkAnything::Storage::Frontend::HTTP; |
5
|
|
|
|
|
|
|
# git description: v0.010-2-ga53a505 |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:SCHWIGON'; |
8
|
|
|
|
|
|
|
# ABSTRACT: Access a BenchmarkAnything store via HTTP |
9
|
|
|
|
|
|
|
$BenchmarkAnything::Storage::Frontend::HTTP::VERSION = '0.011'; |
10
|
1
|
|
|
1
|
|
3
|
use Mojo::Base 'Mojolicious'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
require File::HomeDir; # MUST 'require', 'use' conflicts with Mojolicious |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has bacfg => sub |
15
|
|
|
|
|
|
|
{ |
16
|
|
|
|
|
|
|
require BenchmarkAnything::Config; |
17
|
|
|
|
|
|
|
return BenchmarkAnything::Config->new; |
18
|
|
|
|
|
|
|
}; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has balib => sub |
21
|
|
|
|
|
|
|
{ |
22
|
|
|
|
|
|
|
my $self = shift; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
require BenchmarkAnything::Storage::Frontend::Lib; |
25
|
|
|
|
|
|
|
return BenchmarkAnything::Storage::Frontend::Lib->new; |
26
|
|
|
|
|
|
|
}; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has backend => sub |
29
|
|
|
|
|
|
|
{ |
30
|
|
|
|
|
|
|
my $self = shift; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
require BenchmarkAnything::Storage::Backend::SQL; |
33
|
|
|
|
|
|
|
return BenchmarkAnything::Storage::Backend::SQL->new ({ dbh => $self->app->balib->{dbh}, debug => 0 }); |
34
|
|
|
|
|
|
|
}; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# This method will run once at server start. |
39
|
|
|
|
|
|
|
# |
40
|
|
|
|
|
|
|
# IMPORTANT: |
41
|
|
|
|
|
|
|
# ---------- |
42
|
|
|
|
|
|
|
# YOU MUST NOT CALL ->balib() INSIDE startup()! |
43
|
|
|
|
|
|
|
# THAT WOULD INSTANTIATE THE SAME DB CONNECTION FOR MULTIPLE |
44
|
|
|
|
|
|
|
# PREFORKED PROCESSES AND THEREFORE MIX UP TRANSACTIONS. |
45
|
|
|
|
|
|
|
sub startup { |
46
|
1
|
|
|
1
|
1
|
9143
|
my $self = shift; |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
|
|
7
|
$self->log->debug("Using BenchmarkAnything"); |
49
|
1
|
|
|
|
|
118
|
$self->log->debug(" - Configfile: ".$self->app->bacfg->{cfgfile}); |
50
|
0
|
|
|
|
|
|
$self->log->debug(" - Backend: ".$self->app->bacfg->{benchmarkanything}{backend}); |
51
|
0
|
|
|
|
|
|
$self->log->debug(" - DSN: ".$self->app->bacfg->{benchmarkanything}{storage}{backend}{sql}{dsn}); |
52
|
|
|
|
|
|
|
die |
53
|
|
|
|
|
|
|
"Config backend:".$self->app->bacfg->{benchmarkanything}{backend}. |
54
|
|
|
|
|
|
|
"' not yet supported (".$self->app->bacfg->{cfgfile}. |
55
|
|
|
|
|
|
|
"), must be 'local'.\n" |
56
|
0
|
0
|
|
|
|
|
if $self->app->bacfg->{benchmarkanything}{backend} ne 'local'; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
0
|
|
|
|
my $queueing_processing_batch_size = $self->app->bacfg->{benchmarkanything}{storage}{backend}{sql}{queueing}{processing_batch_size} || 100; |
59
|
0
|
|
0
|
|
|
|
my $queueing_processing_sleep = $self->app->bacfg->{benchmarkanything}{storage}{backend}{sql}{queueing}{processing_sleep} || 30; |
60
|
0
|
|
0
|
|
|
|
my $queueing_gc_sleep = $self->app->bacfg->{benchmarkanything}{storage}{backend}{sql}{queueing}{gc_sleep} || 120; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
$self->log->debug(" - Q.batch_size: $queueing_processing_batch_size"); |
63
|
0
|
|
|
|
|
|
$self->log->debug(" - Q.sleep: $queueing_processing_sleep"); |
64
|
0
|
|
|
|
|
|
$self->log->debug(" - Q.gc_sleep: $queueing_gc_sleep"); |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
$self->plugin('InstallablePaths'); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# recurring worker |
69
|
|
|
|
|
|
|
Mojo::IOLoop->recurring($queueing_processing_sleep => sub { |
70
|
0
|
|
|
0
|
|
|
$self->log->debug("process bench queue (batchsize: $queueing_processing_batch_size) [".~~localtime."]"); |
71
|
0
|
|
|
|
|
|
$self->app->balib->process_raw_result_queue($queueing_processing_batch_size); |
72
|
0
|
|
|
|
|
|
}); |
73
|
|
|
|
|
|
|
Mojo::IOLoop->recurring($queueing_gc_sleep => sub { |
74
|
0
|
|
|
0
|
|
|
$self->log->debug("garbage collection [".~~localtime."]"); |
75
|
0
|
|
|
|
|
|
$self->app->balib->gc(); |
76
|
0
|
|
|
|
|
|
}); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# routes |
79
|
0
|
|
|
|
|
|
my $routes = $self->routes; |
80
|
0
|
|
|
|
|
|
$routes |
81
|
|
|
|
|
|
|
->any('/api/v1/search/:value_id' => [value_id => qr/\d+/]) |
82
|
|
|
|
|
|
|
->to('search#search', value_id => 0); |
83
|
0
|
|
|
|
|
|
$routes |
84
|
|
|
|
|
|
|
->any('/api/v1/listnames/:pattern' => [pattern => qr/[^\/]+/]) |
85
|
|
|
|
|
|
|
->to('search#listnames', pattern => ''); |
86
|
0
|
|
|
|
|
|
$routes |
87
|
|
|
|
|
|
|
->any('/api/v1/listkeys/:pattern' => [pattern => qr/[^\/]+/]) |
88
|
|
|
|
|
|
|
->to('search#listkeys', pattern => ''); |
89
|
0
|
|
|
|
|
|
$routes |
90
|
|
|
|
|
|
|
->any('/api/v1/hello') |
91
|
|
|
|
|
|
|
->to('search#hello'); |
92
|
0
|
|
|
|
|
|
$routes |
93
|
|
|
|
|
|
|
->any('/api/v1/add') |
94
|
|
|
|
|
|
|
->to('submit#add'); |
95
|
0
|
|
|
|
|
|
$routes |
96
|
|
|
|
|
|
|
->any('/api/v1/stats') |
97
|
|
|
|
|
|
|
->to('search#stats'); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__END__ |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=pod |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=encoding UTF-8 |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 NAME |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
BenchmarkAnything::Storage::Frontend::HTTP - Access a BenchmarkAnything store via HTTP |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 AUTHOR |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Steffen Schwigon <ss5@renormalist.net> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Steffen Schwigon. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
121
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |