You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Utilize tools provided to you in the container to inspect what's happening in your Memgraph instance. Send us diagnostics, so we're able to identify issues quicker and make the product more stable.
4
4
---
5
5
import { Steps } from'nextra/components'
6
6
import { Callout } from'nextra/components'
7
7
8
-
# Debugging Memgraph by yourself
8
+
# Debugging Memgraph
9
9
10
-
###Why do we expose users with the capability of debugging Memgraph?
10
+
## Why enable user debugging?
11
11
12
-
In the process of enhancing Memgraph's performance and reliability, user-driven debugging plays a crucial role. Given the complex nature of software environments, it is often challenging for our team to address all issues simultaneously. Moreover, bugs can exhibit behaviors that are difficult to replicate on different systems.
12
+
User-driven debugging helps improve Memgraph's performance and reliability by
13
+
providing diagnostic data from your environment. This data assists us in
14
+
reproducing and resolving issues faster, especially for bugs that are hard to
15
+
replicate.
13
16
14
-
By conducting initial debugging, users can provide us with valuable diagnostic data from their specific environment, which is essential for reproducing and pinpointing the root cause of issues. To facilitate this, we have equipped our container with a suite of user-friendly tools designed to assist in the debugging process.
17
+
To help with this, our containers come equipped with user-friendly debugging
18
+
tools, empowering you to identify and report problems more effectively.
15
19
16
-
These tools not only empower users to identify and report problems more accurately but also expedite the resolution process, enhancing overall system stability and performance.
20
+
## Chose the right debug image
17
21
18
-
### Which Memgraph image can I use to debug Memgraph?
22
+
Memgraph provides Docker images built in `RelWithDebInfo` mode, including tools
23
+
like `perf`, `gdb` and `pgrep`. This image is about 10% slower but enables
24
+
detailed debugging.
19
25
20
-
Memgraph offers Docker images specifically tailored for debugging, with Memgraph built in the **RelWithDebInfo** mode. These containers are equipped with crucial debugging tools such as **perf, gdb, and pgrep**, along with other useful apt packages.
26
+
To pull a debug image:
21
27
22
-
This setup is intended to empower users to conduct thorough investigations into issues such as slow performance, system hangs, or unusually high memory usage. Although the RelWithDebInfo build mode of Memgraph comes with some performance degradations (**~10% slower performance overall**), this approach contributes to more stable and efficient system performance in the long run.
23
-
24
-
After identification of all the issues and moving to production, users are encouraged to switch to Release mode, with the default Memgraph images, to make sure they gain the extra performance, from the now fast and reliable system.
25
-
26
-
Memgraph in the RelWithDebInfo mode can be downloaded from DockerHub with the following command:
Where `memgraph_version` and `MAGE_version` are the respective versions of the image. All the images in the `RelWithDebInfo` build
39
-
mode have the suffix `-relwithdebinfo`.
37
+
All the images in the `RelWithDebInfo` build mode have the suffix
38
+
`-relwithdebinfo`.
39
+
40
+
## Run Memgraph in debug mode
40
41
41
-
### I have the Memgraph image, is there anything specific I should do to run Memgraph?
42
-
Yes, Memgraph container needs to be run in the **--privileged mode**. Privileged mode is an option of the Docker ecosystem, not Memgraph. It will allow for gdb and perf tools to run properly.
42
+
Run the Memgraph container in privileged mode to allow debugging tools like
43
+
`gdb` and `perf`to function:
43
44
44
-
Below, we can see an example command of how to run a Memgraph container in the privileged mode:
45
+
Below, we can see an example command of how to run a Memgraph container in the
@@ -91,14 +102,17 @@ Most likely, the Memgraph process will have the PID number 1, but for certainty,
91
102
|`info args`| Prints function arguments of the current frame. |
92
103
|`print $local_var`| Prints the value of the variable `$local_var`. |
93
104
94
-
### Most commonly used commands.
95
-
In Memgraph, we usually want to see first what are all the threads currently in place. We do that by issuing:
105
+
106
+
107
+
In Memgraph, we usually want to see first what are all the threads currently in
108
+
place. We do that by issuing:
96
109
97
110
```bash
98
111
info thread
99
112
```
100
113
101
-
By identifying a certain thread with a code that could belong to the Memgraph repository, we can issue the command
114
+
By identifying a certain thread with a code that could belong to the Memgraph
115
+
repository, we can issue the command
102
116
103
117
```bash
104
118
t <x>
@@ -110,26 +124,36 @@ Seeing the backtrace can be done with the command
110
124
bt
111
125
```
112
126
113
-
##2. Generating a core dump with Memgraph
127
+
### Generating core dump via Docker
114
128
115
-
### Generating a core dump with a plain Docker image
116
-
In order to generate a core dump, you need to do a few steps on the host and in the container image.
129
+
In order to generate a core dump, you need to do a few steps on the host and in
130
+
the container image.
117
131
118
-
1. Setting no size limit to the core dump
119
-
Initially, you will need to set no boundaries to the size of the core dump that can be generated. This is done with the following command:
132
+
<Steps>
133
+
{<h4className="custom-header">Set no size limit to the core dump</h4>}
134
+
135
+
Initially, you will need to set no boundaries to the size of the core dump that
136
+
can be generated. This is done with the following command:
120
137
121
138
```bash
122
139
ulimit -c unlimited
123
140
```
124
141
125
-
2. Mounting the correct volume
126
-
When Memgraph crashes, we would want to get the present core dump file on our host system. When starting the container, we will provide the appropriate volume. Additionally, don't forget to set the `--privileged` flag as noted in the previous sections.
142
+
{<h4className="custom-header">Mount the correct volume</h4>}
143
+
144
+
When Memgraph crashes, we would want to get the present core dump file on our
145
+
host system. When starting the container, we will provide the appropriate
146
+
volume. Additionally, don't forget to set the `--privileged` flag as noted in
3. Setting up the container for core dump generation
132
-
Additionally, in the container, the following commands will need to be executed after the container has started, to be able to generate a correct core dump.
153
+
{<h4className="custom-header">Set up the container</h4>}
154
+
155
+
Additionally, in the container, the following commands will need to be executed
156
+
after the container has started, to be able to generate a correct core dump.
When Memgraph crashes, a core dump will be generated, and you will see it on the host system if you have mounted the volume correctly.
165
+
When Memgraph crashes, a core dump will be generated, and you will see it on the
166
+
host system if you have mounted the volume correctly.
167
+
168
+
{<h4className="custom-header">Inspecting the container</h4>}
142
169
143
-
4. Starting Memgraph again and inspecting the core dump with `GDB`
144
-
The container will need to be started again since we want the same debug symbols to be present, and using an identical image is the most proper way for that. However, we don't need now the Memgraph process at port 7687, so we will ignore it.
170
+
The container will need to be started again since we want the same debug symbols
171
+
to be present, and using an identical image is the most proper way for that.
172
+
However, we don't need now the Memgraph process at port 7687, so we will ignore
173
+
it.
145
174
146
-
You will need to copy the core dump file into the container with the `docker cp` command.
175
+
You will need to copy the core dump file into the container with the `docker cp`
176
+
command.
147
177
148
178
After logging into the container with the root credentials:
179
+
149
180
```bash
150
181
docker container exec -it -u root memgraph bash
151
182
```
@@ -156,12 +187,20 @@ we will execute `GDB` with the core dump file provided
where the `core.memgraph.file` is the name of your core dump file. Possibly, appropriate permissions will need to be set on the core dump file. You can check the list of useful `GDB` commands in the above sections.
190
+
where the `core.memgraph.file` is the name of your core dump file. Possibly,
191
+
appropriate permissions will need to be set on the core dump file. You can check
192
+
the list of useful `GDB` commands in the above sections.
160
193
161
-
To find out more about setting core dumps, you can check [this article](https://medium.com/@sourabhedake/core-dumps-how-to-enable-them-73856a437711).
194
+
To find out more about setting core dumps, you can check [this
The setup with Docker Compose is similar to Docker. You will need to bind the volume, run Memgraph in privileged mode, and make sure you set no size limit on the generated core dump.
197
+
</Steps>
198
+
199
+
### Generating core dump via Docker Compose
200
+
201
+
The setup with Docker Compose is similar to Docker. You will need to bind the
202
+
volume, run Memgraph in privileged mode, and make sure you set no size limit on
203
+
the generated core dump.
165
204
166
205
Below we can see an example Docker Compose file which can generate a core dump:
167
206
@@ -196,53 +235,78 @@ services:
196
235
```
197
236
198
237
199
-
## 3. Using`perf` to identify performance bottlenecks
238
+
### Profiling with`perf`
200
239
201
-
Perfing is the most common operation that is run when Memgraph is hanging or performing slowly.
240
+
Perfing is the most common operation that is run when Memgraph is hanging or
241
+
performing slowly.
202
242
203
-
In the next steps, the instructions are provided on how to check which parts of Memgraph are stalling during query execution, so we can use the information to make the system better.
243
+
In the next steps, the instructions are provided on how to check which parts of
244
+
Memgraph are stalling during query execution, so we can use the information to
245
+
make the system better.
204
246
205
-
Prior to performing perf instructions, you will need to bound the Memgraph binary to the local filesystem.
206
-
You can start Memgraph with the volume binded like this:
247
+
Prior to performing perf instructions, you will need to bound the Memgraph
248
+
binary to the local filesystem. You can start Memgraph with the volume binded
Perfing Memgraph Inside the container, we will need to perf the system. That is
259
+
done using the following command.
214
260
215
261
```bash
216
262
perf record -p $(pgrep memgraph) --call-graph dwarf sleep 5
217
263
```
218
264
219
-
The command will perf the Memgraph process for 5 seconds. Of course, you can tweak the number by yourself. The command will generate a file called `perf.data` in the directory you have performed the command in the container
265
+
The command will perf the Memgraph process for 5 seconds. Of course, you can
266
+
tweak the number by yourself. The command will generate a file called
267
+
`perf.data`in the directory you have performed the command in the container
220
268
221
-
2. Installing `hotspot` as the GUI tool on the host
222
-
On the outside, we will need to install a GUI tool called `hotspot`, that will help us generate a [flamegraph](https://www.brendangregg.com/flamegraphs.html). We can install `hotspot` on the host machine by issuing the command:
We will need to install a GUI tool called `hotspot`, that will help us generate
273
+
a [flamegraph](https://www.brendangregg.com/flamegraphs.html). We can install
274
+
`hotspot` on the host machine by issuing the command:
223
275
224
276
```bash
225
277
apt install hotspot
226
278
```
227
279
228
-
if your machine does not support APT, please check the [hotspot repo](https://github.com/KDAB/hotspot) and follow the installation steps.
280
+
If your machine does not support APT, please check the [hotspot
281
+
repo](https://github.com/KDAB/hotspot) and follow the installation steps.
282
+
283
+
284
+
{<h4 className="custom-header">Copy `perf.data` to host</h4>}
285
+
286
+
After we have perfed the data, we need to get the perf information from the
287
+
container to the host. That is done with the following command **on the host**
229
288
230
-
3. Transferring `perf.data` to host
231
-
After we have perfed the data, we need to get the perf information from the container to the host. That is done with the following command **on the host**
232
289
```bash
233
290
docker cp <container_id>:<path_to_perf.data> .
234
291
```
235
292
236
-
where the `container_id` is the Memgraph container ID, and the `path_to_perf.data` is the absolute path in the container to the generated `perf.data` file.
293
+
where the `container_id` is the Memgraph container ID, and the
294
+
`path_to_perf.data`is the absolute path in the container to the generated
295
+
`perf.data`file.
237
296
238
-
4. Linking Memgraph's debug symbols in the container to the host
239
-
For `hotspot` to be able to identify debug symbols and draw the flamegraph, it needs the path to the debug symbols to be the exact one as in the container. In the container it is the `/usr/lib/memgraph/memgraph` binary, so we will need to make a symbolic link from the container volume to the host system:
@@ -412,29 +478,33 @@ To enable core dumps, create a `values.yaml` file with at least the following se
412
478
createCoreDumpsClaim: true
413
479
```
414
480
415
-
Setting this value to true will also enable the use of GDB inside Memgraph containers when using our provided [charts](https://github.com/memgraph/helm-charts).
481
+
Setting this value to true will also enable the use of GDB inside Memgraph
Feel free to copy values file from the [helm-charts repository](https://github.com/memgraph/helm-charts) as a base, since additional required fields may be missing from a minimal config.
419
-
</Callout>
485
+
<Callouttype="info"> Feel free to copy values file from the [helm-charts
486
+
repository](https://github.com/memgraph/helm-charts) as a base, since additional
487
+
required fields may be missing from a minimal config. </Callout>
420
488
421
-
This instructs the Helm chart to create a `PersistentVolumeClaim` (PVC) to
422
-
store core dumps generated by the Memgraph process.
489
+
This instructs the Helm chart to create a `PersistentVolumeClaim` (PVC) to store
**By default the storage size is 10GiB**. Core dumps can be as large as your node's total RAM, so it's recommended to set this explicitly and make sure to adjust the `coreDumpsStorageSize` under
427
-
`values.yaml` file.
494
+
**By default the storage size is 10GiB**. Core dumps can be as large as your
495
+
node's total RAM, so it's recommended to set this explicitly and make sure to
496
+
adjust the `coreDumpsStorageSize` under `values.yaml` file.
428
497
429
-
**Make sure to use the `relwithdebinfo` image** of Memgraph by setting the `image.tag` also under `values.yaml` file.
498
+
**Make sure to use the `relwithdebinfo` image** of Memgraph by setting the
499
+
`image.tag` also under `values.yaml` file.
430
500
431
501
Run the following command to install Memgraph with the debugging configuration:
0 commit comments