File: groonga-httpd.html

package info (click to toggle)
groonga 11.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 121,576 kB
  • sloc: ansic: 801,209; javascript: 62,121; ruby: 46,206; cpp: 33,790; xml: 24,951; yacc: 13,333; sh: 7,776; python: 3,266; makefile: 2,315; perl: 133
file content (702 lines) | stat: -rw-r--r-- 42,897 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702


<!DOCTYPE html>

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>7.1.5. groonga-httpd &#8212; Groonga v10.1.1-31-g1e46ba6 documentation</title>
    <link rel="stylesheet" href="../../_static/groonga.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
    <script src="../../_static/jquery.js"></script>
    <script src="../../_static/underscore.js"></script>
    <script src="../../_static/doctools.js"></script>
    <script src="../../_static/language_data.js"></script>
    
    <link rel="shortcut icon" href="../../_static/favicon.ico"/>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="7.1.6. Groonga HTTP server" href="groonga-server-http.html" />
    <link rel="prev" title="7.1.4. groonga-benchmark" href="groonga-benchmark.html" /> 
  </head><body>
<div class="header">
  <h1 class="title">
    <a id="top-link" href="../../index.html">
      <span class="project">groonga</span>
      <span class="separator">-</span>
      <span class="description">An open-source fulltext search engine and column store.</span>
    </a>
  </h1>

  <div class="other-language-links">
    <ul>
      <li><a href="../../../../ja/html/reference/executables/groonga-httpd.html">日本語</a></li>
    </ul>
  </div>
</div>
  

    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="groonga-server-http.html" title="7.1.6. Groonga HTTP server"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="groonga-benchmark.html" title="7.1.4. groonga-benchmark"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">Groonga v10.1.1-31-g1e46ba6 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../reference.html" ><span class="section-number">7. </span>Reference manual</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../executables.html" accesskey="U"><span class="section-number">7.1. </span>Executables</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href=""><span class="section-number">7.1.5. </span>groonga-httpd</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="groonga-httpd">
<h1><span class="section-number">7.1.5. </span>groonga-httpd<a class="headerlink" href="#groonga-httpd" title="Permalink to this headline">¶</a></h1>
<div class="section" id="summary">
<h2><span class="section-number">7.1.5.1. </span>Summary<a class="headerlink" href="#summary" title="Permalink to this headline">¶</a></h2>
<p>groonga-httpd is a program to communicate with a Groonga server using
the HTTP protocol. It functions as same as
<a class="reference internal" href="groonga-server-http.html"><span class="doc">Groonga HTTP server</span></a>. Although <a class="reference internal" href="groonga-server-http.html"><span class="doc">Groonga HTTP server</span></a> has
limited support for HTTP with a minimal built-in HTTP server,
groonga-httpd has full support for HTTP with an embedded <a class="reference external" href="http://nginx.org/">nginx</a>. All standards-compliance and features provided
by nginx is also available in groonga-httpd.</p>
<p>groonga-httpd has an Web-based administration tool implemented with HTML and
JavaScript. You can access to it from <a class="reference external" href="http://hostname:port/">http://hostname:port/</a>.</p>
</div>
<div class="section" id="syntax">
<h2><span class="section-number">7.1.5.2. </span>Syntax<a class="headerlink" href="#syntax" title="Permalink to this headline">¶</a></h2>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>groonga-httpd [nginx options]
</pre></div>
</div>
</div>
<div class="section" id="usage">
<h2><span class="section-number">7.1.5.3. </span>Usage<a class="headerlink" href="#usage" title="Permalink to this headline">¶</a></h2>
<div class="section" id="set-up">
<h3><span class="section-number">7.1.5.3.1. </span>Set up<a class="headerlink" href="#set-up" title="Permalink to this headline">¶</a></h3>
<p>First, you’ll need to edit the groonga-httpd configuration file to specify a
database. Edit /etc/groonga/httpd/groonga-httpd.conf to enable the
<code class="docutils literal notranslate"><span class="pre">groonga_database</span></code> directive like this:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span># Match this to the file owner of groonga database files if groonga-httpd is
# run as root.
#user groonga;
...
http {
  ...
  # Don&#39;t change the location; currently only /d/ is supported.
  location /d/ {
    groonga on; # &lt;= This means to turn on groonga-httpd.

    # Specify an actual database and enable this.
    groonga_database /var/lib/groonga/db/db;
  }
  ...
}
</pre></div>
</div>
<p>Then, run groonga-httpd. Note that the control immediately returns back to the
console because groonga-httpd runs as a daemon process by default.:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>% groonga-httpd
</pre></div>
</div>
</div>
<div class="section" id="request-queries">
<h3><span class="section-number">7.1.5.3.2. </span>Request queries<a class="headerlink" href="#request-queries" title="Permalink to this headline">¶</a></h3>
<p>To check, request a simple query (<a class="reference internal" href="../commands/status.html"><span class="doc">status</span></a>).</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>% curl http://localhost:10041/d/status
[
  [
    0,
    1337566253.89858,
    0.000355720520019531
  ],
  {
    &quot;uptime&quot;: 1,
    &quot;max_command_version&quot;: 3,
    &quot;start_time&quot;: 1514346019,
    &quot;cache_hit_rate&quot;: 0.0,
    &quot;version&quot;: &quot;7.0.9&quot;,
    &quot;alloc_count&quot;: 13365,
    &quot;command_version&quot;: 1,
    &quot;starttime&quot;: 1514346019,
    &quot;default_command_version&quot;: 1,
    &quot;n_queries&quot;: 0
  }
]
</pre></div>
</div>
</div>
<div class="section" id="loading-data-by-post">
<h3><span class="section-number">7.1.5.3.3. </span>Loading data by POST<a class="headerlink" href="#loading-data-by-post" title="Permalink to this headline">¶</a></h3>
<p>You can load data by POST JSON data.</p>
<p>Here is an example <code class="docutils literal notranslate"><span class="pre">curl</span></code> command line that loads two users <code class="docutils literal notranslate"><span class="pre">alice</span></code>
and <code class="docutils literal notranslate"><span class="pre">bob</span></code> to <code class="docutils literal notranslate"><span class="pre">Users</span></code> table:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>% curl --data-binary &#39;[{&quot;_key&quot;: &quot;alice&quot;}, {&quot;_key&quot;: &quot;bob&quot;}]&#39; -H &quot;Content-Type: application/json&quot; &quot;http://localhost:10041/d/load?table=Users&quot;
</pre></div>
</div>
<p>If you loads users from JSON file, prepare JSON file like this:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>[
{&quot;_key&quot;: &quot;alice&quot;},
{&quot;_key&quot;: &quot;bob&quot;}
]
</pre></div>
</div>
<p>Then specify JSON file in <code class="docutils literal notranslate"><span class="pre">curl</span></code> command line:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>% curl -X POST &#39;http://localhost:10041/d/load?table=Users&#39; -H &#39;Content-Type: application/json&#39; -d @users.json
</pre></div>
</div>
</div>
<div class="section" id="browse-the-administration-tool">
<h3><span class="section-number">7.1.5.3.4. </span>Browse the administration tool<a class="headerlink" href="#browse-the-administration-tool" title="Permalink to this headline">¶</a></h3>
<p>Also, you can browse Web-based administration tool at <a class="reference external" href="http://localhost:10041/">http://localhost:10041/</a>.</p>
</div>
<div class="section" id="shut-down">
<h3><span class="section-number">7.1.5.3.5. </span>Shut down<a class="headerlink" href="#shut-down" title="Permalink to this headline">¶</a></h3>
<p>Finally, to terminate the running groonga-httpd daemon, run this:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>% groonga-httpd -s stop
</pre></div>
</div>
</div>
</div>
<div class="section" id="configuration-directives">
<h2><span class="section-number">7.1.5.4. </span>Configuration directives<a class="headerlink" href="#configuration-directives" title="Permalink to this headline">¶</a></h2>
<p>This section describes only important directives. They are
groonga-httpd specific directives and performance related directives.</p>
<p>The following directives can be used in the groonga-httpd configuration file.
By default, it’s located at /etc/groonga/httpd/groonga-httpd.conf.</p>
<div class="section" id="groonga-httpd-specific-directives">
<h3><span class="section-number">7.1.5.4.1. </span>Groonga-httpd specific directives<a class="headerlink" href="#groonga-httpd-specific-directives" title="Permalink to this headline">¶</a></h3>
<p>The following directives aren’t provided by nginx. They are provided
by groonga-httpd to configure groonga-httpd specific configurations.</p>
<div class="section" id="groonga">
<h4><span class="section-number">7.1.5.4.1.1. </span><code class="docutils literal notranslate"><span class="pre">groonga</span></code><a class="headerlink" href="#groonga" title="Permalink to this headline">¶</a></h4>
<p>Syntax:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>groonga on | off;
</pre></div>
</div>
<dl class="simple">
<dt>Default</dt><dd><p><code class="docutils literal notranslate"><span class="pre">groonga</span> <span class="pre">off;</span></code></p>
</dd>
<dt>Context</dt><dd><p><code class="docutils literal notranslate"><span class="pre">location</span></code></p>
</dd>
</dl>
<p>Specifies whether Groonga is enabled in the <code class="docutils literal notranslate"><span class="pre">location</span></code> block. The
default is <code class="docutils literal notranslate"><span class="pre">off</span></code>. You need to specify <code class="docutils literal notranslate"><span class="pre">on</span></code> to enable groonga.</p>
<p>Examples:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>location /d/ {
  groonga on;  # Enables groonga under /d/... path
}

location /d/ {
  groonga off; # Disables groonga under /d/... path
}
</pre></div>
</div>
</div>
<div class="section" id="groonga-database">
<span id="groonga-httpd-groonga-database"></span><h4><span class="section-number">7.1.5.4.1.2. </span><code class="docutils literal notranslate"><span class="pre">groonga_database</span></code><a class="headerlink" href="#groonga-database" title="Permalink to this headline">¶</a></h4>
<p>Syntax:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>groonga_database /path/to/groonga/database;
</pre></div>
</div>
<dl class="simple">
<dt>Default</dt><dd><p><code class="docutils literal notranslate"><span class="pre">groonga_database</span> <span class="pre">/usr/local/var/lib/groonga/db/db;</span></code></p>
</dd>
<dt>Context</dt><dd><p><code class="docutils literal notranslate"><span class="pre">http</span></code>, <code class="docutils literal notranslate"><span class="pre">server</span></code>, <code class="docutils literal notranslate"><span class="pre">location</span></code></p>
</dd>
</dl>
<p>Specifies the path to a Groonga database. This is the required
directive.</p>
</div>
<div class="section" id="groonga-database-auto-create">
<span id="groonga-httpd-groonga-database-auto-create"></span><h4><span class="section-number">7.1.5.4.1.3. </span><code class="docutils literal notranslate"><span class="pre">groonga_database_auto_create</span></code><a class="headerlink" href="#groonga-database-auto-create" title="Permalink to this headline">¶</a></h4>
<p>Syntax:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>groonga_database_auto_create on | off;
</pre></div>
</div>
<dl class="simple">
<dt>Default</dt><dd><p><code class="docutils literal notranslate"><span class="pre">groonga_database_auto_create</span> <span class="pre">on;</span></code></p>
</dd>
<dt>Context</dt><dd><p><code class="docutils literal notranslate"><span class="pre">http</span></code>, <code class="docutils literal notranslate"><span class="pre">server</span></code>, <code class="docutils literal notranslate"><span class="pre">location</span></code></p>
</dd>
</dl>
<p>Specifies whether Groonga database is created automatically or not. If
the value is <code class="docutils literal notranslate"><span class="pre">on</span></code> and the Groonga database specified by
<a class="reference internal" href="#groonga-httpd-groonga-database"><span class="std std-ref">groonga_database</span></a> doesn’t exist, the Groonga
database is created automatically. If the Groonga database exists,
groonga-httpd does nothing.</p>
<p>If parent directory doesn’t exist, parent directory is also created
recursively.</p>
<p>The default value is <code class="docutils literal notranslate"><span class="pre">on</span></code>. Normally, the value doesn’t need to be
changed.</p>
</div>
<div class="section" id="groonga-base-path">
<h4><span class="section-number">7.1.5.4.1.4. </span><code class="docutils literal notranslate"><span class="pre">groonga_base_path</span></code><a class="headerlink" href="#groonga-base-path" title="Permalink to this headline">¶</a></h4>
<p>Syntax:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>groonga_base_path /d/;
</pre></div>
</div>
<dl class="simple">
<dt>Default</dt><dd><p>The same value as <code class="docutils literal notranslate"><span class="pre">location</span></code> name.</p>
</dd>
<dt>Context</dt><dd><p><code class="docutils literal notranslate"><span class="pre">location</span></code></p>
</dd>
</dl>
<p>Specifies the base path in URI. Groonga uses
<code class="docutils literal notranslate"><span class="pre">/d/command?parameter1=value1&amp;...</span></code> path to run <code class="docutils literal notranslate"><span class="pre">command</span></code>. The form
of path in used in groonga-httpd but groonga-httpd also supports
<code class="docutils literal notranslate"><span class="pre">/other-prefix/command?parameter1=value1&amp;...</span></code> form. To support the
form, groonga-httpd removes the base path from the head of request URI
and prepend <code class="docutils literal notranslate"><span class="pre">/d/</span></code> to the processed request URI. By the path
conversion, users can use custom path prefix and Groonga can always
uses <code class="docutils literal notranslate"><span class="pre">/d/command?parameter1=value1&amp;...</span></code> form.</p>
<p>Nomally, this directive isn’t needed. It is needed for per command
configuration.</p>
<p>Here is an example configuration to add authorization to
<a class="reference internal" href="../commands/shutdown.html"><span class="doc">shutdown</span></a> command:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>groonga_database /var/lib/groonga/db/db;

location /d/shutdown {
  groonga on;
  # groonga_base_path is needed.
  # Because /d/shutdown is handled as the base path.
  # Without this configuration, /d/shutdown/shutdown path is required
  # to run shutdown command.
  groonga_base_path /d/;
  auth_basic           &quot;manager is required!&quot;;
  auth_basic_user_file &quot;/etc/managers.htpasswd&quot;;
}

location /d/ {
  groonga on;
  # groonga_base_path doesn&#39;t needed.
  # Because location name is the base path.
}
</pre></div>
</div>
</div>
<div class="section" id="groonga-log-path">
<span id="groonga-httpd-groonga-log-path"></span><h4><span class="section-number">7.1.5.4.1.5. </span><code class="docutils literal notranslate"><span class="pre">groonga_log_path</span></code><a class="headerlink" href="#groonga-log-path" title="Permalink to this headline">¶</a></h4>
<p>Syntax:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>groonga_log_path path | off;
</pre></div>
</div>
<dl class="simple">
<dt>Default</dt><dd><p><code class="docutils literal notranslate"><span class="pre">/var/log/groonga/httpd/groonga.log</span></code></p>
</dd>
<dt>Context</dt><dd><p><code class="docutils literal notranslate"><span class="pre">http</span></code>, <code class="docutils literal notranslate"><span class="pre">server</span></code>, <code class="docutils literal notranslate"><span class="pre">location</span></code></p>
</dd>
</dl>
<p>Specifies Groonga log path in the <code class="docutils literal notranslate"><span class="pre">http</span></code>, <code class="docutils literal notranslate"><span class="pre">server</span></code> or <code class="docutils literal notranslate"><span class="pre">location</span></code> block. The
default is <code class="docutils literal notranslate"><span class="pre">/var/log/groonga/httpd/groonga.log</span></code>.
You can disable logging to specify <code class="docutils literal notranslate"><span class="pre">off</span></code>.</p>
<p>Examples:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>location /d/ {
  groonga on;
  # You can disable log for groonga.
  groonga_log_path off;
}
</pre></div>
</div>
</div>
<div class="section" id="groonga-log-level">
<span id="groonga-httpd-groonga-log-level"></span><h4><span class="section-number">7.1.5.4.1.6. </span><code class="docutils literal notranslate"><span class="pre">groonga_log_level</span></code><a class="headerlink" href="#groonga-log-level" title="Permalink to this headline">¶</a></h4>
<p>Syntax:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>groonga_log_level none | emergency | alert | ciritical | error | warning | notice | info | debug | dump;
</pre></div>
</div>
<dl class="simple">
<dt>Default</dt><dd><p><code class="docutils literal notranslate"><span class="pre">notice</span></code></p>
</dd>
<dt>Context</dt><dd><p><code class="docutils literal notranslate"><span class="pre">http</span></code>, <code class="docutils literal notranslate"><span class="pre">server</span></code>, <code class="docutils literal notranslate"><span class="pre">location</span></code></p>
</dd>
</dl>
<p>Specifies Groonga log level in the <code class="docutils literal notranslate"><span class="pre">http</span></code>, <code class="docutils literal notranslate"><span class="pre">server</span></code> or <code class="docutils literal notranslate"><span class="pre">location</span></code> block. The
default is <code class="docutils literal notranslate"><span class="pre">notice</span></code>. You can disable logging by specifying <code class="docutils literal notranslate"><span class="pre">none</span></code> as log level.</p>
<p>Examples:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>location /d/ {
  groonga on;
  # You can customize log level for groonga.
  groonga_log_level notice;
}
</pre></div>
</div>
</div>
<div class="section" id="groonga-query-log-path">
<span id="groonga-httpd-groonga-query-log-path"></span><h4><span class="section-number">7.1.5.4.1.7. </span><code class="docutils literal notranslate"><span class="pre">groonga_query_log_path</span></code><a class="headerlink" href="#groonga-query-log-path" title="Permalink to this headline">¶</a></h4>
<p>Syntax:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>groonga_query_log_path path | off;
</pre></div>
</div>
<dl class="simple">
<dt>Default</dt><dd><p><code class="docutils literal notranslate"><span class="pre">/var/log/groonga/httpd/groonga-query.log</span></code></p>
</dd>
<dt>Context</dt><dd><p><code class="docutils literal notranslate"><span class="pre">http</span></code>, <code class="docutils literal notranslate"><span class="pre">server</span></code>, <code class="docutils literal notranslate"><span class="pre">location</span></code></p>
</dd>
</dl>
<p>Specifies Groonga’s query log path in the <code class="docutils literal notranslate"><span class="pre">http</span></code>, <code class="docutils literal notranslate"><span class="pre">server</span></code> or
<code class="docutils literal notranslate"><span class="pre">location</span></code> block. The default is
<code class="docutils literal notranslate"><span class="pre">/var/log/groonga/httpd/groonga-query.log</span></code>.  You can disable logging
to specify <code class="docutils literal notranslate"><span class="pre">off</span></code>.</p>
<p>Examples:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>location /d/ {
  groonga on;
  # You can disable query log for groonga.
  groonga_query_log_path off;
}
</pre></div>
</div>
<p>Query log is useful for the following cases:</p>
<blockquote>
<div><ul class="simple">
<li><p>Detecting slow query.</p></li>
<li><p>Debugging.</p></li>
</ul>
</div></blockquote>
<p>You can analyze your query log by <a class="reference external" href="https://github.com/groonga/groonga-query-log">groonga-query-log package</a>. The package provides
useful tools.</p>
<p>For example, there is a tool that analyzing your query log. It can
detect slow queries from your query log. There is a tool that
replaying same queries in your query log. It can test the new Groonga
before updating production environment.</p>
</div>
</div>
<div class="section" id="performance-related-directives">
<h3><span class="section-number">7.1.5.4.2. </span>Performance related directives<a class="headerlink" href="#performance-related-directives" title="Permalink to this headline">¶</a></h3>
<p>The following directives are related to the performance of groonga-httpd.</p>
<div class="section" id="worker-processes">
<h4><span class="section-number">7.1.5.4.2.1. </span><code class="docutils literal notranslate"><span class="pre">worker_processes</span></code><a class="headerlink" href="#worker-processes" title="Permalink to this headline">¶</a></h4>
<p>For optimum performance, set this to be equal to the number of CPUs or cores. In
many cases, Groonga queries may be CPU-intensive work, so to fully utilize
multi-CPU/core systems, it’s essential to set this accordingly.</p>
<p>This isn’t a groonga-httpd specific directive, but an nginx’s one. For details,
see <a class="reference external" href="http://wiki.nginx.org/CoreModule#worker_processes">http://wiki.nginx.org/CoreModule#worker_processes</a>.</p>
<p>By default, this is set to 1. It is nginx’s default.</p>
</div>
<div class="section" id="groonga-cache-limit">
<span id="groonga-httpd-groonga-cache-limit"></span><h4><span class="section-number">7.1.5.4.2.2. </span><code class="docutils literal notranslate"><span class="pre">groonga_cache_limit</span></code><a class="headerlink" href="#groonga-cache-limit" title="Permalink to this headline">¶</a></h4>
<p>Syntax:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>groonga_cache_limit limit;
</pre></div>
</div>
<dl class="simple">
<dt>Default</dt><dd><p><code class="docutils literal notranslate"><span class="pre">groonga_cache_limit</span> <span class="pre">100;</span></code></p>
</dd>
<dt>Context</dt><dd><p><code class="docutils literal notranslate"><span class="pre">http</span></code>, <code class="docutils literal notranslate"><span class="pre">server</span></code>, <code class="docutils literal notranslate"><span class="pre">location</span></code></p>
</dd>
</dl>
<p>Specifies Groonga’s limit of query cache in the <code class="docutils literal notranslate"><span class="pre">http</span></code>, <code class="docutils literal notranslate"><span class="pre">server</span></code> or
<code class="docutils literal notranslate"><span class="pre">location</span></code> block. The default value is 100.
You can disable query cache to specify 0 to <code class="docutils literal notranslate"><span class="pre">groonga_cache_limit</span></code> explicitly.</p>
<p>Examples:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>location /d/ {
  groonga on;
  # You can customize query cache limit for groonga.
  groonga_cache_limit 100;
}
</pre></div>
</div>
</div>
<div class="section" id="groonga-cache-base-path">
<span id="groonga-httpd-groonga-cache-base-path"></span><h4><span class="section-number">7.1.5.4.2.3. </span><code class="docutils literal notranslate"><span class="pre">groonga_cache_base_path</span></code><a class="headerlink" href="#groonga-cache-base-path" title="Permalink to this headline">¶</a></h4>
<p>Syntax:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>groonga_cache_base_path path | off;
</pre></div>
</div>
<dl class="simple">
<dt>Default</dt><dd><p><code class="docutils literal notranslate"><span class="pre">groonga_cache_base_path</span> <span class="pre">off;</span></code></p>
</dd>
<dt>Context</dt><dd><p><code class="docutils literal notranslate"><span class="pre">http</span></code>, <code class="docutils literal notranslate"><span class="pre">server</span></code>, <code class="docutils literal notranslate"><span class="pre">location</span></code></p>
</dd>
</dl>
<p>Specifies the base path of query cache in the <code class="docutils literal notranslate"><span class="pre">http</span></code>, <code class="docutils literal notranslate"><span class="pre">server</span></code> or
<code class="docutils literal notranslate"><span class="pre">location</span></code> block.</p>
<p>It’s recommended that you specify this configuration when you use
multi-workers configuration.</p>
<p>If the base path is specified, you can use persistent cache instead of
on memory cache. If you use persistent cache, workers share query
cache. It’s efficient for multi-workers configuration because the same
response is cached only once in multiple workers.</p>
<p>There is one more merit for persistent cache. You don’t need to warm
up cache after groonga-httpd is restarted. Persistent cache isn’t
cleared when groonga-httpd is down. groonga-httpd can use existing
persistent cache again.</p>
<p>The default value is <code class="docutils literal notranslate"><span class="pre">off</span></code>. It means that persistent cache is
disabled. On memory cache is used. On memory cache is independent in
each worker. It’s not efficient for multi-workers configuration
because two or more workers may keeps the same response separately.</p>
<p>Persistent cache is a bit slower than on memory cache. Normally, the
difference has little influence on performance.</p>
<p>You must specify the base path on memory file system. If you specify
the base path on disk, your cache will be slow. It’s not make sense.</p>
<p>Examples:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>location /d/ {
  groonga on;
  # You can customize query cache limit for groonga.
  groonga_cache_base_path /dev/shm/groonga-httpd-cache;
}
</pre></div>
</div>
</div>
<div class="section" id="proxy-cache">
<h4><span class="section-number">7.1.5.4.2.4. </span><code class="docutils literal notranslate"><span class="pre">proxy_cache</span></code><a class="headerlink" href="#proxy-cache" title="Permalink to this headline">¶</a></h4>
<p>In short, you can use nginx’s reverse proxy and cache mechanism
instead of Groonga’s built-in query cache feature.</p>
<div class="section" id="query-cache">
<h5><span class="section-number">7.1.5.4.2.4.1. </span>Query cache<a class="headerlink" href="#query-cache" title="Permalink to this headline">¶</a></h5>
<p>Groonga has query cache feature for <a class="reference internal" href="../commands/select.html"><span class="doc">select</span></a>
command. The feature improves performance in many cases.</p>
<p>Query cache feature works well on groonga-httpd except you use
<a class="reference internal" href="../commands/cache_limit.html"><span class="doc">cache_limit</span></a> command on 2 or more
workers. Normally, <a class="reference internal" href="../commands/cache_limit.html"><span class="doc">cache_limit</span></a> command
isn’t used. So there is no problem on many cases.</p>
<p>Here is a description about a problem of using
<a class="reference internal" href="../commands/cache_limit.html"><span class="doc">cache_limit</span></a> command on 2 or more workers.</p>
<p>Groonga’s query cache is available in the same process. It means that
workers can’t share the cache. If you don’t change cache size, it
isn’t a big problem. If you want to change cache size by
<a class="reference internal" href="../commands/cache_limit.html"><span class="doc">cache_limit</span></a> command, there is a problem.</p>
<p>There is no portable ways to change cache size for all workers.</p>
<p>For example, there are 3 workers:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>                                   +-- worker 1
client -- groonga-httpd (master) --+-- worker 2
                                   +-- worker 3
</pre></div>
</div>
<p>The client requests <a class="reference internal" href="../commands/cache_limit.html"><span class="doc">cache_limit</span></a> command and
the worker 1 receives it:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>                                   +-&gt; worker 1 (changed!)
client -&gt; groonga-httpd (master) --+-- worker 2
                                   +-- worker 3
</pre></div>
</div>
<p>The client requests <a class="reference internal" href="../commands/cache_limit.html"><span class="doc">cache_limit</span></a> command
again and the worker 1 receives it again:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>                                   +-&gt; worker 1 (changed again!!!)
client -&gt; groonga-httpd (master) --+-- worker 2
                                   +-- worker 3
</pre></div>
</div>
<p>In this case, the worker 2 and the worker 3 aren’t received any
requests. So they don’t change cache size.</p>
<p>You can’t choose a worker. So you can’t change cache sizes of all
workers by <a class="reference internal" href="../commands/cache_limit.html"><span class="doc">cache_limit</span></a> command.</p>
</div>
<div class="section" id="reverse-proxy-and-cache">
<h5><span class="section-number">7.1.5.4.2.4.2. </span>Reverse proxy and cache<a class="headerlink" href="#reverse-proxy-and-cache" title="Permalink to this headline">¶</a></h5>
<p>You can use nginx’s reverse proxy and cache feature for query cache:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>                                                            +-- worker 1
client -- groonga-httpd (master) -- reverse proxy + cache --+-- worker 2
                                                            +-- worker 3
</pre></div>
</div>
<p>You can use the same cache configuration for all workers but you can’t
change cache configuration dynamically by HTTP.</p>
<p>Here is a sample configuration:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>...
http {
  proxy_cache_path /var/cache/groonga-httpd levels=1:2 keys_zone=groonga:10m;
  proxy_cache_valid 10m;
  ...
  # Reverse proxy and cache
  server {
    listen 10041;
    ...
    # Only select command
    location /d/select {
      # Pass through groonga with cache
      proxy_cache groonga;
      proxy_pass http://localhost:20041;
    }

    location / {
      # Pass through groonga
      proxy_pass http://localhost:20041;
    }
  }

  # groonga
  server {
    location 20041;
    location /d/ {
      groonga on;
      groonga_database /var/lib/groonga/db/db;
    }
  }
  ...
}
</pre></div>
</div>
<p>See the following nginx documentations for parameter details:</p>
<blockquote>
<div><ul class="simple">
<li><p><a class="reference external" href="http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_path">http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_path</a></p></li>
<li><p><a class="reference external" href="http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_valid">http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_valid</a></p></li>
<li><p><a class="reference external" href="http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache">http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache</a></p></li>
<li><p><a class="reference external" href="http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass">http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass</a></p></li>
</ul>
</div></blockquote>
<p>Note that you need to remove cache files created by nginx by hand
after you load new data to Groonga. For the above sample
configuration, run the following command to remove cache files:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>% groonga DB_PATH &lt; load.grn
% rm -rf /var/cache/groonga-httpd/*
</pre></div>
</div>
<p>If you use Groonga’s query cache feature, you don’t need to expire
cache by hand. It is done automatically.</p>
</div>
</div>
</div>
<div class="section" id="nginx-log-related-directives">
<h3><span class="section-number">7.1.5.4.3. </span>nginx log related directives<a class="headerlink" href="#nginx-log-related-directives" title="Permalink to this headline">¶</a></h3>
<div class="section" id="access-log">
<h4><span class="section-number">7.1.5.4.3.1. </span><code class="docutils literal notranslate"><span class="pre">access_log</span></code><a class="headerlink" href="#access-log" title="Permalink to this headline">¶</a></h4>
<p>We can output nginx’s log by the <code class="docutils literal notranslate"><span class="pre">access_log</span></code> directive.
The following example is the default nginx’s log settings:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>http {
  log_format  combined  &#39;$remote_addr - $remote_user [$time_local] &quot;$request&quot; &#39;
                    &#39;$status $body_bytes_sent &quot;$http_referer&quot; &#39;
                    &#39;&quot;$http_user_agent&quot; &quot;$http_x_forwarded_for&quot;&#39;;

  access_log  access.log  combined;
}
</pre></div>
</div>
<p>We can specify log format by <code class="docutils literal notranslate"><span class="pre">log_format</span></code> directive.
For the details of available items of the log,
see <a class="reference external" href="http://nginx.org/en/docs/http/ngx_http_log_module.html">Module ngx_http_log_module</a>.</p>
<p>nginx’s access log is outputted when a requests is processed.
If we want to output the request processing time,
we need to set configuration as below:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>http {
  log_format  combined  &#39;$remote_addr - $remote_user [$time_local] &quot;$request&quot; &#39;
                    &#39;$status $body_bytes_sent &quot;$http_referer&quot; &#39;
                    &#39;&quot;$http_user_agent&quot; &quot;$http_x_forwarded_for&quot; &#39;
                    &#39;&quot;$request_time&quot;&#39;;

  access_log  access.log  combined;
}
</pre></div>
</div>
</div>
</div>
</div>
<div class="section" id="available-nginx-modules">
<h2><span class="section-number">7.1.5.5. </span>Available nginx modules<a class="headerlink" href="#available-nginx-modules" title="Permalink to this headline">¶</a></h2>
<p>All standard HTTP modules are available. HttpRewriteModule is
disabled when you don’t have PCRE (Perl Compatible Regular
Expressions). For the list of standard HTTP modules, see
<a class="reference external" href="http://nginx.org/en/docs/">nginx documentation</a>.</p>
</div>
</div>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">7.1.5. groonga-httpd</a><ul>
<li><a class="reference internal" href="#summary">7.1.5.1. Summary</a></li>
<li><a class="reference internal" href="#syntax">7.1.5.2. Syntax</a></li>
<li><a class="reference internal" href="#usage">7.1.5.3. Usage</a><ul>
<li><a class="reference internal" href="#set-up">7.1.5.3.1. Set up</a></li>
<li><a class="reference internal" href="#request-queries">7.1.5.3.2. Request queries</a></li>
<li><a class="reference internal" href="#loading-data-by-post">7.1.5.3.3. Loading data by POST</a></li>
<li><a class="reference internal" href="#browse-the-administration-tool">7.1.5.3.4. Browse the administration tool</a></li>
<li><a class="reference internal" href="#shut-down">7.1.5.3.5. Shut down</a></li>
</ul>
</li>
<li><a class="reference internal" href="#configuration-directives">7.1.5.4. Configuration directives</a><ul>
<li><a class="reference internal" href="#groonga-httpd-specific-directives">7.1.5.4.1. Groonga-httpd specific directives</a><ul>
<li><a class="reference internal" href="#groonga">7.1.5.4.1.1. <code class="docutils literal notranslate"><span class="pre">groonga</span></code></a></li>
<li><a class="reference internal" href="#groonga-database">7.1.5.4.1.2. <code class="docutils literal notranslate"><span class="pre">groonga_database</span></code></a></li>
<li><a class="reference internal" href="#groonga-database-auto-create">7.1.5.4.1.3. <code class="docutils literal notranslate"><span class="pre">groonga_database_auto_create</span></code></a></li>
<li><a class="reference internal" href="#groonga-base-path">7.1.5.4.1.4. <code class="docutils literal notranslate"><span class="pre">groonga_base_path</span></code></a></li>
<li><a class="reference internal" href="#groonga-log-path">7.1.5.4.1.5. <code class="docutils literal notranslate"><span class="pre">groonga_log_path</span></code></a></li>
<li><a class="reference internal" href="#groonga-log-level">7.1.5.4.1.6. <code class="docutils literal notranslate"><span class="pre">groonga_log_level</span></code></a></li>
<li><a class="reference internal" href="#groonga-query-log-path">7.1.5.4.1.7. <code class="docutils literal notranslate"><span class="pre">groonga_query_log_path</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#performance-related-directives">7.1.5.4.2. Performance related directives</a><ul>
<li><a class="reference internal" href="#worker-processes">7.1.5.4.2.1. <code class="docutils literal notranslate"><span class="pre">worker_processes</span></code></a></li>
<li><a class="reference internal" href="#groonga-cache-limit">7.1.5.4.2.2. <code class="docutils literal notranslate"><span class="pre">groonga_cache_limit</span></code></a></li>
<li><a class="reference internal" href="#groonga-cache-base-path">7.1.5.4.2.3. <code class="docutils literal notranslate"><span class="pre">groonga_cache_base_path</span></code></a></li>
<li><a class="reference internal" href="#proxy-cache">7.1.5.4.2.4. <code class="docutils literal notranslate"><span class="pre">proxy_cache</span></code></a><ul>
<li><a class="reference internal" href="#query-cache">7.1.5.4.2.4.1. Query cache</a></li>
<li><a class="reference internal" href="#reverse-proxy-and-cache">7.1.5.4.2.4.2. Reverse proxy and cache</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#nginx-log-related-directives">7.1.5.4.3. nginx log related directives</a><ul>
<li><a class="reference internal" href="#access-log">7.1.5.4.3.1. <code class="docutils literal notranslate"><span class="pre">access_log</span></code></a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#available-nginx-modules">7.1.5.5. Available nginx modules</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="groonga-benchmark.html"
                        title="previous chapter"><span class="section-number">7.1.4. </span>groonga-benchmark</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="groonga-server-http.html"
                        title="next chapter"><span class="section-number">7.1.6. </span>Groonga HTTP server</a></p>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" />
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="groonga-server-http.html" title="7.1.6. Groonga HTTP server"
             >next</a> |</li>
        <li class="right" >
          <a href="groonga-benchmark.html" title="7.1.4. groonga-benchmark"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">Groonga v10.1.1-31-g1e46ba6 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../reference.html" ><span class="section-number">7. </span>Reference manual</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../executables.html" ><span class="section-number">7.1. </span>Executables</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href=""><span class="section-number">7.1.5. </span>groonga-httpd</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2009-2021, Brazil, Inc.
    </div>
  </body>
</html>