← Index
NYTProf Performance Profile   « line view »
For /home/ss5/perl5/perlbrew/perls/perl-5.22.0/bin/benchmarkanything-storage
  Run on Mon Jan 29 16:55:34 2018
Reported on Mon Jan 29 16:57:07 2018

Filename/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/Search/Elasticsearch.pm
StatementsExecuted 31042 statements in 74.5ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
100111106ms1.85sSearch::Elasticsearch::::newSearch::Elasticsearch::new
111653µs2.64msSearch::Elasticsearch::::BEGIN@6Search::Elasticsearch::BEGIN@6
111377µs2.16msSearch::Elasticsearch::::BEGIN@5Search::Elasticsearch::BEGIN@5
11116µs28µsSearch::Elasticsearch::::BEGIN@3Search::Elasticsearch::BEGIN@3
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;
2
3344µs241µs
# spent 28µs (16+13) within Search::Elasticsearch::BEGIN@3 which was called: # once (16µs+13µs) by BenchmarkAnything::Storage::Search::Elasticsearch::get_elasticsearch_client at line 3
use Moo 1.003 ();
# spent 28µs making 1 call to Search::Elasticsearch::BEGIN@3 # spent 12µs making 1 call to UNIVERSAL::VERSION
4
5268µs22.27ms
# spent 2.16ms (377µs+1.78) within Search::Elasticsearch::BEGIN@5 which was called: # once (377µs+1.78ms) by BenchmarkAnything::Storage::Search::Elasticsearch::get_elasticsearch_client at line 5
use Search::Elasticsearch::Util qw(parse_params load_plugin);
# spent 2.16ms making 1 call to Search::Elasticsearch::BEGIN@5 # spent 112µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337]
62334µs22.75ms
# spent 2.64ms (653µs+1.98) within Search::Elasticsearch::BEGIN@6 which was called: # once (653µs+1.98ms) by BenchmarkAnything::Storage::Search::Elasticsearch::get_elasticsearch_client at line 6
use namespace::clean;
# spent 2.64ms making 1 call to Search::Elasticsearch::BEGIN@6 # spent 109µs making 1 call to namespace::clean::import
7
81300nsour $VERSION = '5.01';
9
1013µsmy %Default_Plugins = (
11 client => [ 'Search::Elasticsearch::Client', '5_0::Direct' ],
12 cxn_factory => [ 'Search::Elasticsearch::Cxn::Factory', '' ],
13 cxn_pool => [ 'Search::Elasticsearch::CxnPool', 'Static' ],
14 logger => [ 'Search::Elasticsearch::Logger', 'LogAny' ],
15 serializer => [ 'Search::Elasticsearch::Serializer', 'JSON' ],
16 transport => [ 'Search::Elasticsearch::Transport', '' ],
17);
18
191600nsmy @Load_Order = qw(
20 serializer
21 logger
22 cxn_factory
23 cxn_pool
24 transport
25 client
26);
27
28#===================================
29
# spent 1.85s (106ms+1.74) within Search::Elasticsearch::new which was called 1001 times, avg 1.84ms/call: # 1001 times (106ms+1.74s) by BenchmarkAnything::Storage::Search::Elasticsearch::get_elasticsearch_client at line 28 of BenchmarkAnything/Storage/Search/Elasticsearch.pm, avg 1.84ms/call
sub new {
30#===================================
3110013.75ms10017.63ms my ( $class, $params ) = parse_params(@_);
# spent 7.63ms making 1001 calls to Search::Elasticsearch::Util::parse_params, avg 8µs/call
32
3310011.13ms $params->{cxn} ||= 'HTTPTiny';
3410011.14ms my $plugins = delete $params->{plugins} || [];
351001904µs $plugins = [$plugins] unless ref $plugins eq 'ARRAY';
36
3710011.31ms for my $name (@Load_Order) {
3860066.93ms my ( $base, $default ) = @{ $Default_Plugins{$name} };
3960062.24ms my $sub_class = $params->{$name} || $default;
4060066.18ms6006481ms my $plugin_class = load_plugin( $base, $sub_class );
# spent 481ms making 6006 calls to Search::Elasticsearch::Util::load_plugin, avg 80µs/call
41600639.0ms60061.18s $params->{$name} = $plugin_class->new($params);
# spent 856ms making 1001 calls to Search::Elasticsearch::CxnPool::Static::new, avg 856µs/call # spent 118ms making 1001 calls to Search::Elasticsearch::Cxn::Factory::new, avg 118µs/call # spent 115ms making 1001 calls to Search::Elasticsearch::Transport::new, avg 115µs/call # spent 57.2ms making 1000 calls to BenchmarkAnything::Storage::Search::Elasticsearch::Serializer::JSON::DontTouchMyUTF8::new, avg 57µs/call # spent 18.5ms making 1001 calls to Search::Elasticsearch::Logger::LogAny::new, avg 18µs/call # spent 18.0ms making 1001 calls to Search::Elasticsearch::Client::5_0::Direct::new, avg 18µs/call # spent 624µs making 1 call to Search::Elasticsearch::Serializer::JSON::new
42 }
43
4410011.06ms for my $name (@$plugins) {
45 my $plugin_class
46 = load_plugin( 'Search::Elasticsearch::Plugin', $name );
47 $plugin_class->_init_plugin($params);
48 }
49
50100110.3ms return $params->{client};
51}
52
5314µs1;
54
55=pod
56
57=encoding UTF-8
58
59=head1 NAME
60
61Search::Elasticsearch - The official client for Elasticsearch
62
63=head1 VERSION
64
65version 5.01
66
67=head1 SYNOPSIS
68
69 use Search::Elasticsearch;
70
71 # Connect to localhost:9200:
72
73 my $e = Search::Elasticsearch->new();
74
75 # Round-robin between two nodes:
76
77 my $e = Search::Elasticsearch->new(
78 nodes => [
79 'search1:9200',
80 'search2:9200'
81 ]
82 );
83
84 # Connect to cluster at search1:9200, sniff all nodes and round-robin between them:
85
86 my $e = Search::Elasticsearch->new(
87 nodes => 'search1:9200',
88 cxn_pool => 'Sniff'
89 );
90
91 # Index a document:
92
93 $e->index(
94 index => 'my_app',
95 type => 'blog_post',
96 id => 1,
97 body => {
98 title => 'Elasticsearch clients',
99 content => 'Interesting content...',
100 date => '2013-09-24'
101 }
102 );
103
104 # Get the document:
105
106 my $doc = $e->get(
107 index => 'my_app',
108 type => 'blog_post',
109 id => 1
110 );
111
112 # Search:
113
114 my $results = $e->search(
115 index => 'my_app',
116 body => {
117 query => {
118 match => { title => 'elasticsearch' }
119 }
120 }
121 );
122
123 # Cluster requests:
124
125 $info = $e->cluster->info;
126 $health = $e->cluster->health;
127 $node_stats = $e->cluster->node_stats;
128
129 # Index requests:
130
131 $e->indices->create(index=>'my_index');
132 $e->indices->delete(index=>'my_index');
133
134=head1 DESCRIPTION
135
136L<Search::Elasticsearch> is the official Perl client for Elasticsearch,
137supported by L<elasticsearch.com|http://www.elasticsearch.com>. Elasticsearch
138itself is a flexible and powerful open source, distributed real-time
139search and analytics engine for the cloud. You can read more about it
140on L<elastic.co|http://www.elastic.co>.
141
142=head1 PREVIOUS VERSIONS OF ELASTICSEARCH
143
144This version of the client supports the Elasticsearch 5.0 branch,
145which is not backwards compatible with earlier branches.
146
147If you need to talk to a version of Elasticsearch before 5.0.0, please
148install one of the following packages:
149
150=over
151
152=item *
153
154L<Search::Elasticsearch::Client::2_0>
155
156=item *
157
158L<Search::Elasticsearch::Client::1_0>
159
160=item *
161
162L<Search::Elasticsearch::Client::0_90>
163
164=back
165
166=head2 Motivation
167
168=over
169
170I<The greatest deception men suffer is from their own opinions.>
171
172Leonardo da Vinci
173
174=back
175
176All of us have opinions, especially when it comes to designing APIs.
177Unfortunately, the opinions of programmers seldom coincide. The intention of
178this client, and of the officially supported clients available for other
179languages, is to provide robust support for the full native Elasticsearch API
180with as few opinions as possible: you should be able to read the
181L<Elasticsearch reference documentation|http://www.elastic.co/guide>
182and understand how to use this client, or any of the other official clients.
183
184Should you decide that you want to customize the API, then this client
185provides the basis for your code. It does the hard stuff for you,
186allowing you to build on top of it.
187
188=head2 Features
189
190This client provides:
191
192=over
193
194=item *
195
196Full support for all Elasticsearch APIs
197
198=item *
199
200HTTP backend (for an async backend using L<Promises>, see
201L<Search::Elasticsearch::Async>)
202
203=item *
204
205Robust networking support which handles load balancing, failure detection
206and failover
207
208=item *
209
210Good defaults
211
212=item *
213
214Helper utilities for more complex operations, such as
215L<bulk indexing|Search::Elasticsearch::Client::5_0::Bulk>, and
216L<scrolled searches|Search::Elasticsearch::Client::5_0::Scroll>
217
218=item *
219
220Logging support via L<Log::Any>
221
222=item *
223
224Compatibility with the official clients for Python, Ruby, PHP, and Javascript
225
226=item *
227
228Easy extensibility
229
230=back
231
232=head1 INSTALLING ELASTICSEARCH
233
234You can download the latest version of Elasticsearch from
235L<http://www.elastic.co/download>. See the
236L<installation instructions|https://www.elastic.co/guide/en/elasticsearch/reference/current/setup.html>
237for details. You will need to have a recent version of Java installed,
238preferably the Java v8 from Sun.
239
240=head1 CREATING A NEW INSTANCE
241
242The L</new()> method returns a new L<client|Search::Elasticsearch::Client::5_0::Direct>
243which can be used to run requests against the Elasticsearch cluster.
244
245 use Search::Elasticsearch;
246 my $e = Search::Elasticsearch->new( %params );
247
248The most important arguments to L</new()> are the following:
249
250=head2 C<nodes>
251
252The C<nodes> parameter tells the client which Elasticsearch nodes it should
253talk to. It can be a single node, multiples nodes or, if not
254specified, will default to C<localhost:9200>:
255
256 # default: localhost:9200
257 $e = Search::Elasticsearch->new();
258
259 # single
260 $e = Search::Elasticsearch->new( nodes => 'search_1:9200');
261
262 # multiple
263 $e = Search::Elasticsearch->new(
264 nodes => [
265 'search_1:9200',
266 'search_2:9200'
267 ]
268 );
269
270Each C<node> can be a URL including a scheme, host, port, path and userinfo
271(for authentication). For instance, this would be a valid node:
272
273 https://username:password@search.domain.com:443/prefix/path
274
275See L<Search::Elasticsearch::Role::Cxn/node> for more on node specification.
276
277=head2 C<cxn_pool>
278
279The L<CxnPool|Search::Elasticsearch::Role::CxnPool> modules manage connections to
280nodes in the Elasticsearch cluster. They handle the load balancing between
281nodes and failover when nodes fail. Which C<CxnPool> you should use depends on
282where your cluster is. There are three choices:
283
284=over
285
286=item * C<Static>
287
288 $e = Search::Elasticsearch->new(
289 cxn_pool => 'Static' # default
290 nodes => [
291 'search1.domain.com:9200',
292 'search2.domain.com:9200'
293 ],
294 );
295
296The L<Static|Search::Elasticsearch::CxnPool::Static> connection pool, which is the
297default, should be used when you don't have direct access to the Elasticsearch
298cluster, eg when you are accessing the cluster through a proxy. See
299L<Search::Elasticsearch::CxnPool::Static> for more.
300
301=item * C<Sniff>
302
303 $e = Search::Elasticsearch->new(
304 cxn_pool => 'Sniff',
305 nodes => [
306 'search1:9200',
307 'search2:9200'
308 ],
309 );
310
311The L<Sniff|Search::Elasticsearch::CxnPool::Sniff> connection pool should be used
312when you B<do> have direct access to the Elasticsearch cluster, eg when
313your web servers and Elasticsearch servers are on the same network.
314The nodes that you specify are used to I<discover> the cluster, which is
315then I<sniffed> to find the current list of live nodes that the cluster
316knows about. See L<Search::Elasticsearch::CxnPool::Sniff>.
317
318=item * C<Static::NoPing>
319
320 $e = Search::Elasticsearch->new(
321 cxn_pool => 'Static::NoPing'
322 nodes => [
323 'proxy1.domain.com:80',
324 'proxy2.domain.com:80'
325 ],
326 );
327
328The L<Static::NoPing|Search::Elasticsearch::CxnPool::Static::NoPing> connection
329pool should be used when your access to a remote cluster is so limited
330that you cannot ping individual nodes with a C<HEAD /> request.
331
332See L<Search::Elasticsearch::CxnPool::Static::NoPing> for more.
333
334=back
335
336=head2 C<trace_to>
337
338For debugging purposes, it is useful to be able to dump the actual HTTP
339requests which are sent to the cluster, and the response that is received.
340This can be enabled with the C<trace_to> parameter, as follows:
341
342 # To STDERR
343 $e = Search::Elasticsearch->new(
344 trace_to => 'Stderr'
345 );
346
347 # To a file
348 $e = Search::Elasticsearch->new(
349 trace_to => ['File','/path/to/filename']
350 );
351
352Logging is handled by L<Log::Any>. See L<Search::Elasticsearch::Logger::LogAny>
353for more information.
354
355=head2 Other
356
357Other arguments are explained in the respective L<module docs|/MODULES>.
358
359=head1 RUNNING REQUESTS
360
361When you create a new instance of Search::Elasticsearch, it returns a
362L<client|Search::Elasticsearch::Client::5_0::Direct> object, which can be used for
363running requests.
364
365 use Search::Elasticsearch;
366 my $e = Search::Elasticsearch->new( %params );
367
368 # create an index
369 $e->indices->create( index => 'my_index' );
370
371 # index a document
372 $e->index(
373 index => 'my_index',
374 type => 'blog_post',
375 id => 1,
376 body => {
377 title => 'Elasticsearch clients',
378 content => 'Interesting content...',
379 date => '2013-09-24'
380 }
381 );
382
383See L<Search::Elasticsearch::Client::5_0::Direct> for more details about the requests that
384can be run.
385
386=head1 MODULES
387
388Each chunk of functionality is handled by a different module,
389which can be specified in the call to L<new()> as shown in L<cxn_pool> above.
390For instance, the following will use the L<Search::Elasticsearch::CxnPool::Sniff>
391module for the connection pool.
392
393 $e = Search::Elasticsearch->new(
394 cxn_pool => 'Sniff'
395 );
396
397Custom modules can be named with the appropriate prefix,
398eg C<Search::Elasticsearch::CxnPool::>, or by prefixing the full class name
399with C<+>:
400
401 $e = Search::Elasticsearch->new(
402 cxn_pool => '+My::Custom::CxnClass'
403 );
404
405The modules that you can override are specified with the following
406arguments to L</new()>:
407
408=head2 C<client>
409
410The class to use for the client functionality, which provides
411methods that can be called to execute requests, such as
412C<search()>, C<index()> or C<delete()>. The client parses the user's
413requests and passes them to the L</transport> class to be executed.
414
415The default version of the client is C<5_0::Direct>, which can
416be explicitly specified as follows:
417
418 $e = Search::Elasticsearch->new(
419 client => '5_0::Direct'
420 );
421
422=head2 C<transport>
423
424The Transport class accepts a parsed request from the L</client> class,
425fetches a L</cxn> from its L</cxn_pool> and tries to execute the request,
426retrying after failure where appropriate. See:
427
428=over
429
430=item * L<Search::Elasticsearch::Transport>
431
432=back
433
434=head2 C<cxn>
435
436The class which handles raw requests to Elasticsearch nodes.
437See:
438
439=over
440
441=item * L<Search::Elasticsearch::Cxn::HTTPTiny> (default)
442
443=item * L<Search::Elasticsearch::Cxn::Hijk>
444
445=item * L<Search::Elasticsearch::Cxn::LWP>
446
447=item * L<Search::Elasticsearch::Cxn::NetCurl>
448
449=back
450
451=head2 C<cxn_factory>
452
453The class which the L</cxn_pool> uses to create new L</cxn> objects.
454See:
455
456=over
457
458=item * L<Search::Elasticsearch::Cxn::Factory>
459
460=back
461
462=head2 C<cxn_pool> (2)
463
464The class to use for the L<connection pool|/cxn_pool> functionality.
465It calls the L</cxn_factory> class to create new L</cxn> objects when
466appropriate. See:
467
468=over
469
470=item * L<Search::Elasticsearch::CxnPool::Static> (default)
471
472=item * L<Search::Elasticsearch::CxnPool::Sniff>
473
474=item * L<Search::Elasticsearch::CxnPool::Static::NoPing>
475
476=back
477
478=head2 C<logger>
479
480The class to use for logging events and tracing HTTP requests/responses. See:
481
482=over
483
484=item * L<Search::Elasticsearch::Logger::LogAny>
485
486=back
487
488=head2 C<serializer>
489
490The class to use for serializing request bodies and deserializing response
491bodies. See:
492
493=over
494
495=item * L<Search::Elasticsearch::Serializer::JSON> (default)
496
497=item * L<Search::Elasticsearch::Serializer::JSON::Cpanel>
498
499=item * L<Search::Elasticsearch::Serializer::JSON::XS>
500
501=item * L<Search::Elasticsearch::Serializer::JSON::PP>
502
503=back
504
505=head1 BUGS
506
507This is a stable API but this implementation is new. Watch this space
508for new releases.
509
510If you have any suggestions for improvements, or find any bugs, please report
511them to L<http://github.com/elasticsearch/elasticsearch-perl/issues>.
512I will be notified, and then you'll automatically be notified of progress on
513your bug as I make changes.
514
515=head1 SUPPORT
516
517You can find documentation for this module with the perldoc command.
518
519 perldoc Search::Elasticsearch
520
521You can also look for information at:
522
523=over 4
524
525=item * GitHub
526
527L<http://github.com/elasticsearch/elasticsearch-perl>
528
529=item * CPAN Ratings
530
531L<http://cpanratings.perl.org/d/Search::Elasticsearch>
532
533=item * Search MetaCPAN
534
535L<https://metacpan.org/module/Search::Elasticsearch>
536
537=item * IRC
538
539The L<#elasticsearch|irc://irc.freenode.net/elasticsearch> channel on
540C<irc.freenode.net>.
541
542=item * Mailing list
543
544The main L<Elasticsearch mailing list|http://discuss.elastic.co>.
545
546=back
547
548=head1 TEST SUITE
549
550The full test suite requires a live Elasticsearch node to run, and should
551be run as :
552
553 perl Makefile.PL
554 ES=localhost:9200 make test
555
556B<TESTS RUN IN THIS WAY ARE DESTRUCTIVE! DO NOT RUN AGAINST A CLUSTER WITH
557DATA YOU WANT TO KEEP!>
558
559You can change the Cxn class which is used by setting the C<ES_CXN>
560environment variable:
561
562 ES_CXN=Hijk ES=localhost:9200 make test
563
564=head1 AUTHOR
565
566Clinton Gormley <drtech@cpan.org>
567
568=head1 COPYRIGHT AND LICENSE
569
570This software is Copyright (c) 2016 by Elasticsearch BV.
571
572This is free software, licensed under:
573
574 The Apache License, Version 2.0, January 2004
575
576=cut
577
57818µs173µs__END__