| 1 |
.. -*- rst -*- |
| 2 |
|
| 3 |
Tuning |
| 4 |
====== |
| 5 |
|
| 6 |
Summary |
| 7 |
------- |
| 8 |
|
| 9 |
There are some tuning parameters for handling a large database. |
| 10 |
|
| 11 |
Parameters |
| 12 |
---------- |
| 13 |
|
| 14 |
This section describes tuning parameters. |
| 15 |
|
| 16 |
.. _tuning-max-n-open-files: |
| 17 |
|
| 18 |
The max number of open files per process |
| 19 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 20 |
|
| 21 |
This parameter is for handling a large database. |
| 22 |
|
| 23 |
Groonga creates one or more files per table and column. If your |
| 24 |
database has many tables and columns, Groonga process needs to open |
| 25 |
many files. |
| 26 |
|
| 27 |
System limits the max number of open files per process. So you need to |
| 28 |
relax the limitation. |
| 29 |
|
| 30 |
Here is an expression that compute how many files are opened by |
| 31 |
Groonga:: |
| 32 |
|
| 33 |
3 (for DB) + |
| 34 |
N tables + |
| 35 |
N columns (except index clumns) + |
| 36 |
(N index columns * 2) + |
| 37 |
X (the number of plugins etc.) |
| 38 |
|
| 39 |
Here is an example schema:: |
| 40 |
|
| 41 |
table_create Entries TABLE_HASH_KEY ShortText |
| 42 |
column_create Entries content COLUMN_SCALAR Text |
| 43 |
column_create Entries n_likes COLUMN_SCALAR UInt32 |
| 44 |
table_create Terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto |
| 45 |
column_create Terms entries_key_index COLUMN_INDEX|WITH_POSITION Entries _key |
| 46 |
column_create Terms entries_content_index COLUMN_INDEX|WITH_POSITION Entries content |
| 47 |
|
| 48 |
This example opens at least 11 files:: |
| 49 |
|
| 50 |
3 + |
| 51 |
2 (Entries and Terms) + |
| 52 |
2 (Entries.content and Entries.n_likes) + |
| 53 |
4 (Terms.entries_key_index and Terms.entries_content_index) + |
| 54 |
X = 11 + X |
| 55 |
|
| 56 |
.. _tuning-memory-usage: |
| 57 |
|
| 58 |
Memory usage |
| 59 |
^^^^^^^^^^^^ |
| 60 |
|
| 61 |
This parameter is for handling a large database. |
| 62 |
|
| 63 |
Groonga maps database files onto memory and accesses to them. Groonga |
| 64 |
doesn't maps unnecessary files onto memory. Groonga maps files when |
| 65 |
they are needed. |
| 66 |
|
| 67 |
If you access to all data in database, all database files are mapped |
| 68 |
onto memory. If total size of your database files is 6GiB, your |
| 69 |
Groonga process uses 6GiB memory. |
| 70 |
|
| 71 |
Normally, your all database files aren't mapped onto memory. But it may |
| 72 |
be occurred. It is an example case that you dump your database. |
| 73 |
|
| 74 |
Normally, you must have memory and swap that is larger than |
| 75 |
database. Linux has tuning parameter to work with less memory and swap |
| 76 |
than database size. |
| 77 |
|
| 78 |
.. _tuning-linux: |
| 79 |
|
| 80 |
Linux |
| 81 |
----- |
| 82 |
|
| 83 |
This section describes how to configure parameters on Linux. |
| 84 |
|
| 85 |
.. _tuning-linux-nofile: |
| 86 |
|
| 87 |
``nofile`` |
| 88 |
^^^^^^^^^^ |
| 89 |
|
| 90 |
You can relax the :ref:`tuning-max-n-open-files` parameter by creating |
| 91 |
a configuration file ``/etc/security/limits.d/groonga.conf`` that has |
| 92 |
the following content:: |
| 93 |
|
| 94 |
${USER} soft nofile ${MAX_VALUE} |
| 95 |
${USER} hard nofile ${MAX_VALUE} |
| 96 |
|
| 97 |
If you run Groonga process by ``groonga`` user and your Groonga |
| 98 |
process needs to open less than 10000 files, use the following |
| 99 |
configuration:: |
| 100 |
|
| 101 |
groonga soft nofile 10000 |
| 102 |
groonga hard nofile 10000 |
| 103 |
|
| 104 |
The configuration is applied after your Groonga service is restarted |
| 105 |
or re-login as your ``groonga`` user. |
| 106 |
|
| 107 |
.. _tuning-linux-overcommit-memory: |
| 108 |
|
| 109 |
``vm.overcommit_memory`` |
| 110 |
^^^^^^^^^^^^^^^^^^^^^^^^ |
| 111 |
|
| 112 |
This is :ref:`tuning-memory-usage` related parameter. You can handle a |
| 113 |
database that is larger than your memory and swap by setting |
| 114 |
``vm.overcommit_memory`` kernel parameter to ``1``. ``1`` means that |
| 115 |
Groonga can always map database files onto memory. Groonga recommends |
| 116 |
the configuration. |
| 117 |
|
| 118 |
See `Linux kernel documentation about overcommit |
| 119 |
<https://www.kernel.org/doc/Documentation/vm/overcommit-accounting>`_ |
| 120 |
about ``vm.overcommit_memory`` parameter details. |
| 121 |
|
| 122 |
You can set the configuration by putting a configuration file |
| 123 |
``/etc/sysctl.d/groonga.conf`` that has the following content:: |
| 124 |
|
| 125 |
vm.overcommit_memory = 1 |
| 126 |
|
| 127 |
The configuration can be applied by restarting your system or run the |
| 128 |
following command:: |
| 129 |
|
| 130 |
% sudo sysctl --system |
| 131 |
|
| 132 |
.. _tuning-linux-max-map-count: |
| 133 |
|
| 134 |
``vm.max_map_count`` |
| 135 |
^^^^^^^^^^^^^^^^^^^^ |
| 136 |
|
| 137 |
This is :ref:`tuning-memory-usage` related parameter. You can handle a |
| 138 |
16GiB or more larger size database by increasing ``vm.max_map_count`` |
| 139 |
kernel parameter. The parameter limits the max number of memory maps. |
| 140 |
|
| 141 |
The default value of the kernel parameter may be ``65530`` or |
| 142 |
``65536``. Groonga maps 256KiB memory chunk at one time. If a |
| 143 |
database is larger than 16GiB, Groonga reaches the |
| 144 |
limitation. (``256KiB * 65536 = 16GiB``) |
| 145 |
|
| 146 |
You needs to increase the value of the kernel parameter to handle |
| 147 |
16GiB or more larger size database. For example, you can handle almost |
| 148 |
32GiB size database by ``65536 * 2 = 131072``. You can set the |
| 149 |
configuration by putting a configuration file |
| 150 |
``/etc/sysctl.d/groonga.conf`` that has the following content:: |
| 151 |
|
| 152 |
vm.max_map_count = 131072 |
| 153 |
|
| 154 |
Note that your real configuration file will be the following because |
| 155 |
you already have ``vm.overcommit_memory`` configuration:: |
| 156 |
|
| 157 |
vm.overcommit_memory = 1 |
| 158 |
vm.max_map_count = 131072 |
| 159 |
|
| 160 |
The configuration can be applied by restarting your system or run the |
| 161 |
following command:: |
| 162 |
|
| 163 |
% sudo sysctl -p |
| 164 |
|
| 165 |
FreeBSD |
| 166 |
------- |
| 167 |
|
| 168 |
This section describes how to configure parameters on FreeBSD. |
| 169 |
|
| 170 |
.. _tuning-freebsd-maxfilesperproc: |
| 171 |
|
| 172 |
``kern.maxfileperproc`` |
| 173 |
^^^^^^^^^^^^^^^^^^^^^^^ |
| 174 |
|
| 175 |
TODO |