Insert into a table with 100000 records,each record about 40 bytes,cost 2.3G memory.So is there some way to decrease the memory cost? #83
Comments
Hi there! so the There is a way to get to know this information precisely, but it uses SQLite C API, which I need to integrate into RediSQL. (https://www.sqlite.org/c3ref/memory_highwater.html) First thing I would ask you to do, is to see if is really RediSQL that use all that memory, it should not be. So please, use the Also, please check that you only have RediSQL in that machine, the What does the OS say about the size of the Redis instance? |
Hi siscia, Thank you for your reply. Since i'm not know the 'info memory' command does not report the amount of memory used by Redisql. Before insert into the table,the info memory shows like follows(i choose the empty node 6379): 127.0.0.1:6379> info memory Memoryused_memory:1542120 And now the 6381 node is like follows:
127.0.0.1:6381> info memory Memoryused_memory:2117434112 And the OS information like follows: root@joffier-virtual-machine:~# top PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND |
Hi there! So, from the OS we see a lot of memory used by *:6381, not by *:6379. I guess this is where How much memory you got into this machine? Can you stress it until it gives you OOM? Indeed I can reproduce the problem. Are you using the latest release? |
Hi siscia, The redisSql module is the latest release like follows: RediSQL_v1.0.3-rc04_53a7a1_arm-unknown-linux-gnueabi_release.so The redis version is :redis_version:5.0.5 I allocate 8G memory into the virtual machine. Yeah,the db key 'mydb' is hashed to node 6381,like follows: after insert into the table:
So does that mean the 100000 records indeed cost 2.39G ram memory? But i think this should not be. And i will try insert more data until it gives me OOM. |
I am running it now with valgrind and indeed I see some memory leak. Let me go back to you in a while! |
So, I fixed a memory leak, but I don't believe it is the issue we are looking for. At least I didn't see enough improvements. Anyhow you can get the latest compiled stuff in the tag v1.1.1 after this: https://travis-ci.org/RedBeardLab/rediSQL/jobs/571788918 finish. I want to track down this issue, so I will add the command to get the amount of memory used by SQLite, and with that command, we can compare and see if we are leaking memory somehow. |
Hi siscia, Then i continue insert data into the table. And when the ram memory is not enough,the swap space is used.In the attach file,you can see the detail test. Thank you. |
Hi Joffier, Indeed I find another memory-related problem. The fix brings the use of memory down to 1/3. Can you try the latest release when it becomes available? (CI: https://travis-ci.org/RedBeardLab/rediSQL/builds/571928427) I noticed that you mentioned the ARM build, are you running on ARM? We have the x86 builds as well. Cheers, |
Nope, sorry, found a bug in this implementation. But I really believe to have found your issue. |
Hi Siscia,
Memoryused_memory:2105054720 root@joffier-virtual-machine:/data/redis/module# ps -ef|grep redis-server|grep 6380 Tasks: 234 total, 1 running, 233 sleeping, 0 stopped, 0 zombie PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND Waiting for your good news :D |
We are getting there! The latest version had an issue (aka they break the system) with the virtual tables so I didn't want to publish online. However, you can try it from here. Does it improve the memory situation? |
Hi Siscia, That's great. And it does decrease the memory cost. I also found that the message in command 'info memory',used_memory_human dose not change,used_memory_rss_human have increased from 19.99M to 25.35M. So is that mean the real memory allocate? If you could offer the sqlite3 memory statics command in later version,that's will be wonderful. And from the OS 'top' statics,i could see the total free memory from '7105408B+687248B=7792656B' to '7062972B+710504B=7773496B' .May be some other process cost a little extra memory in the insert procedure. In a word,the OS memory dose not cost so many as before. Thank you!
Memory # Memoryused_memory:1541928 used_memory:1543144 Before:
107332 root 20 0 486644 14540 6300 S 0.3 0.2 0:00.86 redis-server After:
120560 root 20 0 43692 3768 3012 R 0.7 0.0 0:03.03 top |
Let me re-format this:
Before:
After:
So we have an increase in memory reported by redis of ~5.35MB which is inline with what we expect give the size of the database file. Great! I will ship out a new release very soon (hopefully) addressing the virtual table issue. Also, very quickly I want to add the new command for getting the size of the database. Thanks very much for reporting the issue! Let me know if there is more I can do for you. I am not yet quite sure about the memory usage reported by the OS but hopefully is nothing too wrong! |
i meet the same problem,does it have been solved? |
|
Hello! Unfortunately the orginal user didn't reply anymore, so the issue was just closed. From my tests seems that the issue was solved, can you try with the linked binary? If that works we can do a nice and clean release for you! Cheers, |
thanks very much. you have said that the version of redisql_1.1.2.tar.gz had an issue (aka they break the system) with the virtual tables. so Can i use the fts of redisql_1.1.2.tar.gz? wait for your release for me,thanks. |
Let's see if I can find some times in the immediate future for the release. I don't expect any problem with FTS on the 1.1.2, virtual tables are another quite complex beast. I believe you are good to go with the 1.1.2 |
Hummm, no, now that I read better, I don't believe an official 1.1.2 is going to be released. We will move directly to 2. |
I don't know the difference,i support you |
what do you mean about “The latest version had an issue (aka they break the system) with the virtual tables so I didn't want to publish online.” |
No, I was referring to the virtual tables in redisql. This one: https://redisql.redbeardlab.com/rediSQL/references/#virtual-tables The FTS do not have any problem that I am aware of. |
Environmet:
virtual-machine ubuntu x86_64 8C 8G
redis5.0 cluster mode,with 3 master nodes,no slave
create db and table sql:
REDISQL.REDISQL.CREATE_DB DB_DEVICE
REDISQL.EXEC DB_DEVICE "create table device_tab (seq TEXT,deviceId TEXT,customerId TEXT,tranName TEXT,time TEXT);"
REDISQL.EXEC DB_DEVICE "create index idx_deviceId on device_tab(deviceId);"
insert shell:
#!/bin/bash
for var in $(seq 1 100000)
do
redis-cli -c -p 6381 REDISQL.EXEC DB_DEVICE "insert into device_tab values('007','did3','2019081304','MonInfoUdt','154006');"
echo $var
done
after insert into the table:
127.0.0.1:6381> REDISQL.EXEC mydb "select count(*) from device_tab;"
127.0.0.1:6381> info memory
Memory
used_memory:2117413200
used_memory_human:1.97G
used_memory_rss:2565685248
used_memory_rss_human:2.39G
So i think this cost too many memory.And is there something wrong what i did or is there some way to decrease the memory cost?
By the way,i create the same table and index just use sqlite3 with disk mode.And insert about 100000 records(each is same with above redisql insert record).The disk file is 5.9M.
root@joffier-virtual-machine:/data/sqlite# sqlite3 mydb.sqlite "select count(*) from device_tab"
101757
root@joffier-virtual-machine:/data/sqlite# ls -lh
总用量 5.9M
-rw-r--r-- 1 root root 159 8月 14 14:19 batchInsert.sh
-rw-r--r-- 1 root root 5.9M 8月 14 14:37 mydb.sqlite
Hope your reply sincely. Thank you!
The text was updated successfully, but these errors were encountered: