Debian Codegraph @

doc/source/server/http/comparison.rst

raw
1 .. -*- rst -*-
2
3 Comparison
4 ==========
5
6 There are many differences between :doc:`groonga` and
7 :doc:`groonga-httpd`. Here is a comparison table.
8
9 +----------------------------+------------------------+----------------------+
10 | | groonga | groonga-httpd |
11 +============================+========================+======================+
12 | Performance | o | o |
13 +----------------------------+------------------------+----------------------+
14 | Using multi CPU cores | o (by multi threading) | o (by multi process) |
15 +----------------------------+------------------------+----------------------+
16 | Configuration file | optional | required |
17 +----------------------------+------------------------+----------------------+
18 | Custom prefix path | x | o |
19 +----------------------------+------------------------+----------------------+
20 | Custom command version | o | o |
21 +----------------------------+------------------------+----------------------+
22 | Multi databases | x | o |
23 +----------------------------+------------------------+----------------------+
24 | Authentication | x | o |
25 +----------------------------+------------------------+----------------------+
26 | Gzip compression | x | o |
27 +----------------------------+------------------------+----------------------+
28 | POST | o | o |
29 +----------------------------+------------------------+----------------------+
30 | HTTPS | x | o |
31 +----------------------------+------------------------+----------------------+
32 | Access log | x | o |
33 +----------------------------+------------------------+----------------------+
34 | Upgrading without downtime | x | o |
35 +----------------------------+------------------------+----------------------+
36
37 Performance
38 -----------
39
40 Both :doc:`groonga` and :doc:`groonga-httpd` are very fast. They can
41 work with the same throughput.
42
43 Using multi CPU cores
44 ---------------------
45
46 Groonga scales on multi CPU cores. :doc:`groonga` scales by multi
47 threading. :doc:`groonga-httpd` scales by multi processes.
48
49 :doc:`groonga` uses the same number of threads as CPU cores by
50 default. If you have 8 CPU cores, 8 threads are used by default.
51
52 :doc:`groonga-httpd` uses 1 process by default. You need to set
53 `worker_processes
54 <http://nginx.org/en/docs/ngx_core_module.html#worker_processes>`_
55 directive to use CPU cores. If you have 8 CPU cores, specify
56 ``worker_processes 8`` in configuration file like the following::
57
58 worker_processes 8;
59
60 http {
61 # ...
62 }
63
64 Configuration file
65 ------------------
66
67 :doc:`groonga` can work without configuration file. All configuration
68 items such as port number and the max number of threads can be
69 specified by command line. Configuration file is also used to specify
70 configuration items.
71
72 It's very easy to run groonga HTTP server because :doc:`groonga`
73 requires just a few options to run. Here is the most simple command
74 line to start HTTP server by :doc:`groonga`::
75
76 % groonga --protocol http -d /PATH/TO/DATABASE
77
78 :doc:`groonga-httpd` requires configuration file to run. Here is the
79 most simple configuration file to start HTTP server by
80 :doc:`groonga-httpd`::
81
82 events {
83 }
84
85 http {
86 server {
87 listen 10041;
88
89 location /d/ {
90 groonga on;
91 groonga_database /PATH/TO/DATABASE;
92 }
93 }
94 }
95
96 Custom prefix path
97 ------------------
98
99 :doc:`groonga` accepts a path that starts with ``/d/`` as command URL
100 such as ``http://localhost:10041/d/status``. You cannot change the
101 prefix path ``/d/``.
102
103 :doc:`groonga-httpd` can custom prefix path. For example, you can use
104 ``http://localhost:10041/api/status`` as command URL. Here is a sample
105 configuration to use ``/api/`` as prefix path::
106
107 events {
108 }
109
110 http {
111 server {
112 listen 10041;
113
114 location /api/ { # <- change this
115 groonga on;
116 groonga_database /PATH/TO/DATABASE;
117 }
118 }
119 }
120
121 Custom command version
122 ----------------------
123
124 Groonga has :doc:`/reference/command/command_version` mechanism. It is for
125 upgrading groonga commands with backward compatibility.
126
127 :doc:`groonga` can change the default command version by
128 ``--default-command-version`` option. Here is a sample command line to
129 use command version 2 as the default command version::
130
131 % groonga --protocol http --default-command-version 2 -d /PATH/TO/DATABASE
132
133 :doc:`groonga-httpd` cannot custom the default command version
134 yet. But it will be supported soon. If it is supported, you can
135 provides different command version groonga commands in the same
136 :doc:`groonga-httpd` process. Here is a sample configuration to
137 provide command version 1 commands under ``/api/1/`` and command
138 version 2 commands under ``/api/2/``::
139
140 events {
141 }
142
143 http {
144 server {
145 listen 10041;
146
147 groonga_database /PATH/TO/DATABASE;
148
149 location /api/1/ {
150 groonga on;
151 groonga_default_command_version 1;
152 }
153
154 location /api/2/ {
155 groonga on;
156 groonga_default_command_version 2;
157 }
158 }
159 }
160
161 Multi databases
162 ---------------
163
164 :doc:`groonga` can use only one database in a process.
165
166 :doc:`groonga-httpd` can use one or more databases in a process. Here
167 is a sample configuration to provide ``/tmp/db1`` database under
168 ``/db1/`` path and ``/tmp/db2`` database under ``/db2/`` path::
169
170 events {
171 }
172
173 http {
174 server {
175 listen 10041;
176
177 location /db1/ {
178 groonga on;
179 groonga_database /tmp/db1;
180 }
181
182 location /db2/ {
183 groonga on;
184 groonga_database /tmp/db2;
185 }
186 }
187 }
188
189 Authentication
190 --------------
191
192 HTTP supports authentications such as basic authentication and digest
193 authentication. It can be used for restricting use of danger command such
194 as :doc:`/reference/commands/shutdown`.
195
196 :doc:`groonga` doesn't support any authentications. To restrict use of
197 danger command, other tools such as iptables and reverse proxy are
198 needed.
199
200 :doc:`groonga-httpd` supports basic authentication. Here is a sample
201 configuration to restrict use of :doc:`/reference/commands/shutdown`
202 command::
203
204 events {
205 }
206
207 http {
208 server {
209 listen 10041;
210
211 groonga_database /PATH/TO/DATABASE;
212
213 location /d/shutdown {
214 groonga on;
215 auth_basic "manager is required!";
216 auth_basic_user_file "/etc/managers.htpasswd";
217 }
218
219 location /d/ {
220 groonga on;
221 }
222 }
223 }
224
225 Gzip compression
226 ----------------
227
228 HTTP supports response compression by gzip with ``Content-Encoding:
229 gzip`` response header. It can reduce network flow. It is useful
230 for large search response.
231
232 :doc:`groonga` doesn't support compression. To support compression,
233 reverse proxy is needed.
234
235 :doc:`groonga-httpd` supports gzip compression. Here is a sample
236 configuration to compress response by gzip::
237
238 events {
239 }
240
241 http {
242 server {
243 listen 10041;
244
245 groonga_database /PATH/TO/DATABASE;
246
247 location /d/ {
248 groonga on;
249 gzip on;
250 gzip_types *;
251 }
252 }
253 }
254
255 Note that `gzip_types *` is specified. It's one of the important
256 configuration. `gzip_types` specifies gzip target data formats by MIME
257 types. :doc:`groonga-httpd` returns one of JSON, XML or MessagePack
258 format data. But those formats aren't included in the default value of
259 `gzip_types`. The default value of `gzip_types` is `text/html`.
260
261 To compress response data from :doc:`groonga-httpd` by gzip, you need
262 to specify `gzip_types *` or `gzip_types application/json text/xml
263 application/x-msgpack` explicitly. `gzip_types *` is recommended.
264 There are two reasons for it. The first, groonga may support more
265 formats in the future. The second, all requests for the `location` are
266 processed by groonga. You don't need to consider about other modules.
267
268 POST
269 ----
270
271 You can load your data by POST JSON data. You need follow the
272 following rules to use loading by POST.
273
274 * `Content-Type` header value must be `application/json`.
275 * JSON data is sent as body.
276 * Table name is specified by query parameter such as ``table=NAME``.
277
278 Here is an example curl command line that loads two users `alice` and
279 `bob` to `Users` table::
280
281 % curl --data-binary '[{"_key": "alice"}, {"_key": "bob"}]' -H "Content-Type: application/json" "http://localhost:10041/d/load?table=Users"
282
283 HTTPS
284 -----
285
286 TODO
287
288 Access log
289 ----------
290
291 TODO
292
293 Upgrading without downtime
294 --------------------------
295
296 TODO