← Index
NYTProf Performance Profile   « line view »
For flows_to_es.pl
  Run on Mon May 9 23:27:59 2016
Reported on Mon May 9 23:28:09 2016

Filename/opt/flows/lib/lib/perl5/Search/Elasticsearch/Role/CxnPool.pm
StatementsExecuted 55 statements in 1.34ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1111.35ms1.52msSearch::Elasticsearch::Role::CxnPool::::BEGIN@6Search::Elasticsearch::Role::CxnPool::BEGIN@6
11146µs13.3msSearch::Elasticsearch::Role::CxnPool::::set_cxnsSearch::Elasticsearch::Role::CxnPool::set_cxns
11117µs342µsSearch::Elasticsearch::Role::CxnPool::::BEGIN@3Search::Elasticsearch::Role::CxnPool::BEGIN@3
11114µs26µsSearch::Elasticsearch::Role::CxnPool::::__ANON__[:33]Search::Elasticsearch::Role::CxnPool::__ANON__[:33]
11113µs15µsSearch::Elasticsearch::Role::CxnPool::::next_cxn_numSearch::Elasticsearch::Role::CxnPool::next_cxn_num
11111µs37µsSearch::Elasticsearch::Role::CxnPool::::BEGIN@5Search::Elasticsearch::Role::CxnPool::BEGIN@5
11111µs120µsSearch::Elasticsearch::Role::CxnPool::::BEGIN@7Search::Elasticsearch::Role::CxnPool::BEGIN@7
11111µs23µsSearch::Elasticsearch::Role::CxnPool::::request_okSearch::Elasticsearch::Role::CxnPool::request_ok
1119µs146µsSearch::Elasticsearch::Role::CxnPool::::BEGIN@4Search::Elasticsearch::Role::CxnPool::BEGIN@4
1119µs263µsSearch::Elasticsearch::Role::CxnPool::::BEGIN@9Search::Elasticsearch::Role::CxnPool::BEGIN@9
1119µs145µsSearch::Elasticsearch::Role::CxnPool::::BEGIN@8Search::Elasticsearch::Role::CxnPool::BEGIN@8
1117µs8µsSearch::Elasticsearch::Role::CxnPool::::reset_retriesSearch::Elasticsearch::Role::CxnPool::reset_retries
1117µs43µsSearch::Elasticsearch::Role::CxnPool::::__ANON__[:3]Search::Elasticsearch::Role::CxnPool::__ANON__[:3]
1112µs2µsSearch::Elasticsearch::Role::CxnPool::::_set_cxnsSearch::Elasticsearch::Role::CxnPool::_set_cxns (xsub)
1112µs2µsSearch::Elasticsearch::Role::CxnPool::::seed_nodesSearch::Elasticsearch::Role::CxnPool::seed_nodes (xsub)
3322µs2µsSearch::Elasticsearch::Role::CxnPool::::loggerSearch::Elasticsearch::Role::CxnPool::logger (xsub)
3332µs2µsSearch::Elasticsearch::Role::CxnPool::::cxnsSearch::Elasticsearch::Role::CxnPool::cxns (xsub)
2212µs2µsSearch::Elasticsearch::Role::CxnPool::::_set_current_cxn_numSearch::Elasticsearch::Role::CxnPool::_set_current_cxn_num (xsub)
2222µs2µsSearch::Elasticsearch::Role::CxnPool::::cxn_factorySearch::Elasticsearch::Role::CxnPool::cxn_factory (xsub)
1111µs1µsSearch::Elasticsearch::Role::CxnPool::::__ANON__[:17]Search::Elasticsearch::Role::CxnPool::__ANON__[:17]
1111µs1µsSearch::Elasticsearch::Role::CxnPool::::randomize_cxnsSearch::Elasticsearch::Role::CxnPool::randomize_cxns (xsub)
1111µs1µsSearch::Elasticsearch::Role::CxnPool::::retriesSearch::Elasticsearch::Role::CxnPool::retries (xsub)
111700ns700nsSearch::Elasticsearch::Role::CxnPool::::current_cxn_numSearch::Elasticsearch::Role::CxnPool::current_cxn_num (xsub)
0000s0sSearch::Elasticsearch::Role::CxnPool::::_max_retriesSearch::Elasticsearch::Role::CxnPool::_max_retries
0000s0sSearch::Elasticsearch::Role::CxnPool::::cxns_seeds_strSearch::Elasticsearch::Role::CxnPool::cxns_seeds_str
0000s0sSearch::Elasticsearch::Role::CxnPool::::cxns_strSearch::Elasticsearch::Role::CxnPool::cxns_str
0000s0sSearch::Elasticsearch::Role::CxnPool::::request_failedSearch::Elasticsearch::Role::CxnPool::request_failed
0000s0sSearch::Elasticsearch::Role::CxnPool::::should_mark_deadSearch::Elasticsearch::Role::CxnPool::should_mark_dead
0000s0sSearch::Elasticsearch::Role::CxnPool::::should_retrySearch::Elasticsearch::Role::CxnPool::should_retry
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Search::Elasticsearch::Role::CxnPool;
21500ns$Search::Elasticsearch::Role::CxnPool::VERSION = '2.02';
3452µs3702µs
# spent 43µs (7+36) within Search::Elasticsearch::Role::CxnPool::__ANON__[/opt/flows/lib/lib/perl5/Search/Elasticsearch/Role/CxnPool.pm:3] which was called: # once (7µs+36µs) by import::into at line 34 of Import/Into.pm # spent 342µs (17+325) within Search::Elasticsearch::Role::CxnPool::BEGIN@3 which was called: # once (17µs+325µs) by Module::Runtime::require_module at line 3
use Moo::Role;
# spent 342µs making 1 call to Search::Elasticsearch::Role::CxnPool::BEGIN@3 # spent 325µs making 1 call to Moo::Role::import # spent 36µs making 1 call to strictures::import
4239µs2282µs
# spent 146µs (9+136) within Search::Elasticsearch::Role::CxnPool::BEGIN@4 which was called: # once (9µs+136µs) by Module::Runtime::require_module at line 4
use Search::Elasticsearch::Util qw(parse_params);
5232µs264µs
# spent 37µs (11+27) within Search::Elasticsearch::Role::CxnPool::BEGIN@5 which was called: # once (11µs+27µs) by Module::Runtime::require_module at line 5
use List::Util qw(shuffle);
# spent 37µs making 1 call to Search::Elasticsearch::Role::CxnPool::BEGIN@5 # spent 27µs making 1 call to Exporter::import
62140µs11.52ms
# spent 1.52ms (1.35+173µs) within Search::Elasticsearch::Role::CxnPool::BEGIN@6 which was called: # once (1.35ms+173µs) by Module::Runtime::require_module at line 6
use IO::Select();
# spent 1.52ms making 1 call to Search::Elasticsearch::Role::CxnPool::BEGIN@6
7238µs2230µs
# spent 120µs (11+110) within Search::Elasticsearch::Role::CxnPool::BEGIN@7 which was called: # once (11µs+110µs) by Module::Runtime::require_module at line 7
use Time::HiRes qw(time sleep);
# spent 120µs making 1 call to Search::Elasticsearch::Role::CxnPool::BEGIN@7 # spent 110µs making 1 call to Time::HiRes::import
8236µs2282µs
# spent 145µs (9+137) within Search::Elasticsearch::Role::CxnPool::BEGIN@8 which was called: # once (9µs+137µs) by Module::Runtime::require_module at line 8
use Search::Elasticsearch::Util qw(to_list);
92832µs2518µs
# spent 263µs (9+254) within Search::Elasticsearch::Role::CxnPool::BEGIN@9 which was called: # once (9µs+254µs) by Module::Runtime::require_module at line 9
use namespace::clean;
# spent 263µs making 1 call to Search::Elasticsearch::Role::CxnPool::BEGIN@9 # spent 254µs making 1 call to namespace::clean::import
10
1112µs19µsrequires qw(next_cxn schedule_check);
# spent 9µs making 1 call to Moo::Role::requires
12
1311µs1141µshas 'cxn_factory' => ( is => 'ro', required => 1 );
# spent 141µs making 1 call to Moo::Role::has
1412µs1116µshas 'logger' => ( is => 'ro', required => 1 );
# spent 116µs making 1 call to Moo::Role::has
1511µs1110µshas 'serializer' => ( is => 'ro', required => 1 );
# spent 110µs making 1 call to Moo::Role::has
1611µs1221µshas 'current_cxn_num' => ( is => 'rwp', default => 0 );
# spent 221µs making 1 call to Moo::Role::has
1727µs1218µs
# spent 1µs within Search::Elasticsearch::Role::CxnPool::__ANON__[/opt/flows/lib/lib/perl5/Search/Elasticsearch/Role/CxnPool.pm:17] which was called: # once (1µs+0s) by Search::Elasticsearch::CxnPool::Static::new at line 37 of (eval 86)[Sub/Quote.pm:5]
has 'cxns' => ( is => 'rwp', default => sub { [] } );
# spent 218µs making 1 call to Moo::Role::has
1811µs1110µshas 'seed_nodes' => ( is => 'ro', required => 1 );
# spent 110µs making 1 call to Moo::Role::has
1911µs1120µshas 'retries' => ( is => 'rw', default => 0 );
# spent 120µs making 1 call to Moo::Role::has
2011µs1114µshas 'randomize_cxns' => ( is => 'ro', default => 1 );
# spent 114µs making 1 call to Moo::Role::has
21
22#===================================
23
# spent 26µs (14+11) within Search::Elasticsearch::Role::CxnPool::__ANON__[/opt/flows/lib/lib/perl5/Search/Elasticsearch/Role/CxnPool.pm:33] which was called: # once (14µs+11µs) by Search::Elasticsearch::CxnPool::Static::__ANON__[(eval 82)[/usr/share/perl5/Class/Method/Modifiers.pm:93]:1] at line 1 of (eval 82)[Class/Method/Modifiers.pm:93]
around BUILDARGS => sub {
24#===================================
251400ns my $orig = shift;
2612µs16µs my $params = $orig->(@_);
# spent 6µs making 1 call to Moo::Object::BUILDARGS
2714µs15µs my @seed = grep {$_} to_list( delete $params->{nodes} || ('') );
# spent 5µs making 1 call to Search::Elasticsearch::Util::to_list
28
291400ns @seed = $params->{cxn_factory}->default_host
30 unless @seed;
311800ns $params->{seed_nodes} = \@seed;
3214µs return $params;
3314µs17µs};
# spent 7µs making 1 call to Moo::Role::around
34
35#===================================
36
# spent 15µs (13+2) within Search::Elasticsearch::Role::CxnPool::next_cxn_num which was called: # once (13µs+2µs) by Search::Elasticsearch::CxnPool::Static::next_cxn at line 21 of /opt/flows/lib/lib/perl5/Search/Elasticsearch/CxnPool/Static.pm
sub next_cxn_num {
37#===================================
381200ns my $self = shift;
3913µs1400ns my $cxns = $self->cxns;
# spent 400ns making 1 call to Search::Elasticsearch::Role::CxnPool::cxns
401200ns return unless @$cxns;
4115µs1700ns my $current = $self->current_cxn_num;
4214µs1900ns $self->_set_current_cxn_num( ( $current + 1 ) % @$cxns );
4319µs return $current;
44}
45
46#===================================
47
# spent 13.3ms (46µs+13.2) within Search::Elasticsearch::Role::CxnPool::set_cxns which was called: # once (46µs+13.2ms) by Search::Elasticsearch::Role::CxnPool::Static::BUILD at line 13 of /opt/flows/lib/lib/perl5/Search/Elasticsearch/Role/CxnPool/Static.pm
sub set_cxns {
48#===================================
491300ns my $self = shift;
5015µs1600ns my $factory = $self->cxn_factory;
5124µs110.1ms my @cxns = map { $factory->new_cxn($_) } @_;
# spent 10.1ms making 1 call to Search::Elasticsearch::Cxn::Factory::new_cxn
52132µs222µs @cxns = shuffle @cxns if $self->randomize_cxns;
# spent 21µs making 1 call to List::Util::shuffle # spent 1µs making 1 call to Search::Elasticsearch::Role::CxnPool::randomize_cxns
5317µs12µs $self->_set_cxns( \@cxns );
# spent 2µs making 1 call to Search::Elasticsearch::Role::CxnPool::_set_cxns
5415µs1900ns $self->_set_current_cxn_num(0);
55
5612µs113µs $self->logger->infof( "Current cxns: %s",
# spent 13µs making 1 call to Search::Elasticsearch::Role::Cxn::HTTP::stringify
57112µs2288µs [ map { $_->stringify } @cxns ] );
# spent 287µs making 1 call to Search::Elasticsearch::Role::Logger::infof # spent 600ns making 1 call to Search::Elasticsearch::Role::CxnPool::logger
58
5914µs return;
60}
61
62#===================================
63
# spent 23µs (11+13) within Search::Elasticsearch::Role::CxnPool::request_ok which was called: # once (11µs+13µs) by Search::Elasticsearch::Transport::try {...} at line 30 of /opt/flows/lib/lib/perl5/Search/Elasticsearch/Transport.pm
sub request_ok {
64#===================================
651300ns my ( $self, $cxn ) = @_;
6612µs14µs $cxn->mark_live;
# spent 4µs making 1 call to Search::Elasticsearch::Role::Cxn::mark_live
6715µs18µs $self->reset_retries;
68}
69
70#===================================
71sub request_failed {
72#===================================
73 my ( $self, $cxn, $error ) = @_;
74
75 if ( $error->is( 'Cxn', 'Timeout' ) ) {
76 $cxn->mark_dead if $self->should_mark_dead($error);
77 $self->schedule_check;
78
79 if ( $self->should_retry($error) ) {
80 my $retries = $self->retries( $self->retries + 1 );
81 return 1 if $retries < $self->_max_retries;
82 }
83 }
84 else {
85 $cxn->mark_live if $cxn;
86 }
87 $self->reset_retries;
88 return 0;
89}
90
91#===================================
92sub should_retry {
93#===================================
94 my ( $self, $error ) = @_;
95 return $error->is('Cxn');
96}
97
98#===================================
99sub should_mark_dead {
100#===================================
101 my ( $self, $error ) = @_;
102 return $error->is('Cxn');
103}
104
105#===================================
106sub cxns_str {
107#===================================
108 my $self = shift;
109 join ", ", map { $_->stringify } @{ $self->cxns };
110}
111
112#===================================
113sub cxns_seeds_str {
114#===================================
115 my $self = shift;
116 join ", ", ( map { $_->stringify } @{ $self->cxns } ),
117 @{ $self->seed_nodes };
118}
119
120#===================================
121110µs11µs
# spent 8µs (7+1) within Search::Elasticsearch::Role::CxnPool::reset_retries which was called: # once (7µs+1µs) by Search::Elasticsearch::Role::CxnPool::request_ok at line 67
sub reset_retries { shift->retries(0) }
# spent 1µs making 1 call to Search::Elasticsearch::Role::CxnPool::retries
122sub _max_retries {2}
123#===================================
124
125113µs1;
126
127=pod
128
129=encoding UTF-8
130
131=head1 NAME
132
133Search::Elasticsearch::Role::CxnPool - Provides common functionality to the CxnPool implementations
134
135=head1 VERSION
136
137version 2.02
138
139=head1 DESCRIPTION
140
141See the CxnPool implementations:
142
143=over
144
145=item *
146
147L<Search::Elasticsearch::CxnPool::Static>
148
149=item *
150
151L<Search::Elasticsearch::CxnPool::Sniff>
152
153=item *
154
155L<Search::Elasticsearch::CxnPool::Static::NoPing>
156
157=back
158
159=head1 CONFIGURATION
160
161These configuration options should not be set by the user but are
162documented here for completeness.
163
164=head2 C<randomize_cxns>
165
166By default, the order of cxns passed to L</set_cxns()> is randomized
167before they are stored. Set C<randomize_cxns> to a false value to
168disable.
169
170=head1 METHODS
171
172=head2 C<cxn_factory()>
173
174 $factory = $cxn_pool->cxn_factory
175
176Returns the L<Search::Elasticsearch::Cxn::Factory> object for creating a new
177C<$cxn> instance.
178
179=head2 C<logger()>
180
181 $logger = $cxn_pool->logger
182
183Returns the L<Search::Elasticsearch::Role::Logger>-based object, which
184defaults to L<Search::Elasticsearch::Logger::LogAny>.
185
186=head2 C<serializer()>
187
188 $serializer = $cxn_pool->serializer
189
190Returns the L<Search::Elasticsearch::Role::Serializer>-based object,
191which defaults to L<Search::Elasticsearch::Serializer::JSON>.
192
193=head2 C<current_cxn_num()>
194
195 $num = $cxn_pool->current_cxn_num
196
197Returns the current cxn number, which is an offset into
198the array of cxns set by L</set_cxns()>.
199
200=head2 C<cxns()>
201
202 \@cxns = $cxn_pool->cxns;
203
204Returns the current list of L<Search::Elasticsearch::Role::Cxn>-based
205cxn objects as set by L</set_cxns()>.
206
207=head2 C<seed_nodes()>
208
209 \@seed_nodes = $cxn_pool->seed_nodes
210
211Returns the list of C<nodes> originally specified when calling
212L<Search::Elasticsearch/new()>.
213
214=head2 C<next_cxn_num()>
215
216 $num = $cxn_pool->next_cxn_num;
217
218Returns the number of the next connection, in round-robin fashion. Updates
219the L</current_cxn_num()>.
220
221=head2 C<set_cxns()>
222
223 $cxn_pool->set_cxns(@nodes);
224
225Takes a list of nodes, converts them into L<Search::Elasticsearch::Role::Cxn>-based
226objects and makes them accessible via L</cxns()>.
227
228=head2 C<request_ok()>
229
230 $cxn_pool->request_ok($cxn);
231
232Called when a request by the specified C<$cxn> object has completed successfully.
233Marks the C<$cxn> as live.
234
235=head2 C<request_failed()>
236
237 $should_retry = $cxn_pool->request_failed($cxn,$error);
238
239Called when a request by the specified C<$cxn> object has failed. Returns
240C<1> if the request should be retried or C<0> if it shouldn't.
241
242=head2 C<should_retry()>
243
244 $bool = $cxn_pool->should_retry($error);
245
246Examines the error to decide whether the request should be retried or not.
247By default, only L<Search::Elasticsearch::Error/Search::Elasticsearch::Error::Cxn> errors
248are retried.
249
250=head2 C<should_mark_dead()>
251
252 $bool = $cxn_pool->should_mark_dead($error);
253
254Examines the error to decide whether the C<$cxn> should be marked as dead or not.
255By default, only L<Search::Elasticsearch::Error/Search::Elasticsearch::Error::Cxn> errors
256cause a C<$cxn> to be marked as dead.
257
258=head2 C<cxns_str()>
259
260 $str = $cxn_pool->cxns_str
261
262Returns all L</cxns()> as a string for logging purposes.
263
264=head2 C<cxns_seeds_str()>
265
266 $str = $cxn_pool->cxns_seeeds_str
267
268Returns all L</cxns()> and L</seed_nodes()> as a string for logging purposes.
269
270=head2 C<retries()>
271
272 $retries = $cxn_pool->retries
273
274The number of times the current request has been retried.
275
276=head2 C<reset_retries()>
277
278 $cxn_pool->reset_retries;
279
280Called at the start of a new request to reset the retries count.
281
282=head1 AUTHOR
283
284Clinton Gormley <drtech@cpan.org>
285
286=head1 COPYRIGHT AND LICENSE
287
288This software is Copyright (c) 2016 by Elasticsearch BV.
289
290This is free software, licensed under:
291
292 The Apache License, Version 2.0, January 2004
293
294=cut
295
296119µs1464µs__END__
 
# spent 2µs within Search::Elasticsearch::Role::CxnPool::_set_current_cxn_num which was called 2 times, avg 900ns/call: # once (900ns+0s) by Search::Elasticsearch::Role::CxnPool::next_cxn_num at line 42 # once (900ns+0s) by Search::Elasticsearch::Role::CxnPool::set_cxns at line 54
sub Search::Elasticsearch::Role::CxnPool::_set_current_cxn_num; # xsub
# spent 2µs within Search::Elasticsearch::Role::CxnPool::_set_cxns which was called: # once (2µs+0s) by Search::Elasticsearch::Role::CxnPool::set_cxns at line 53
sub Search::Elasticsearch::Role::CxnPool::_set_cxns; # xsub
# spent 700ns within Search::Elasticsearch::Role::CxnPool::current_cxn_num which was called: # once (700ns+0s) by Search::Elasticsearch::Role::CxnPool::next_cxn_num at line 41
sub Search::Elasticsearch::Role::CxnPool::current_cxn_num; # xsub
# spent 2µs within Search::Elasticsearch::Role::CxnPool::cxn_factory which was called 2 times, avg 750ns/call: # once (900ns+0s) by Search::Elasticsearch::Role::Transport::BUILD at line 22 of /opt/flows/lib/lib/perl5/Search/Elasticsearch/Role/Transport.pm # once (600ns+0s) by Search::Elasticsearch::Role::CxnPool::set_cxns at line 50
sub Search::Elasticsearch::Role::CxnPool::cxn_factory; # xsub
# spent 2µs within Search::Elasticsearch::Role::CxnPool::cxns which was called 3 times, avg 733ns/call: # once (900ns+0s) by Search::Elasticsearch::CxnPool::Static::next_cxn at line 14 of /opt/flows/lib/lib/perl5/Search/Elasticsearch/CxnPool/Static.pm # once (900ns+0s) by Search::Elasticsearch::Role::CxnPool::Static::schedule_check at line 22 of /opt/flows/lib/lib/perl5/Search/Elasticsearch/Role/CxnPool/Static.pm # once (400ns+0s) by Search::Elasticsearch::Role::CxnPool::next_cxn_num at line 39
sub Search::Elasticsearch::Role::CxnPool::cxns; # xsub
# spent 2µs within Search::Elasticsearch::Role::CxnPool::logger which was called 3 times, avg 767ns/call: # once (1µs+0s) by Search::Elasticsearch::Role::CxnPool::Static::schedule_check at line 21 of /opt/flows/lib/lib/perl5/Search/Elasticsearch/Role/CxnPool/Static.pm # once (700ns+0s) by Search::Elasticsearch::Role::CxnPool::Static::schedule_check at line 24 of /opt/flows/lib/lib/perl5/Search/Elasticsearch/Role/CxnPool/Static.pm # once (600ns+0s) by Search::Elasticsearch::Role::CxnPool::set_cxns at line 57
sub Search::Elasticsearch::Role::CxnPool::logger; # xsub
# spent 1µs within Search::Elasticsearch::Role::CxnPool::randomize_cxns which was called: # once (1µs+0s) by Search::Elasticsearch::Role::CxnPool::set_cxns at line 52
sub Search::Elasticsearch::Role::CxnPool::randomize_cxns; # xsub
# spent 1µs within Search::Elasticsearch::Role::CxnPool::retries which was called: # once (1µs+0s) by Search::Elasticsearch::Role::CxnPool::reset_retries at line 121
sub Search::Elasticsearch::Role::CxnPool::retries; # xsub
# spent 2µs within Search::Elasticsearch::Role::CxnPool::seed_nodes which was called: # once (2µs+0s) by Search::Elasticsearch::Role::CxnPool::Static::BUILD at line 13 of /opt/flows/lib/lib/perl5/Search/Elasticsearch/Role/CxnPool/Static.pm
sub Search::Elasticsearch::Role::CxnPool::seed_nodes; # xsub