Use MySQL as a file system (2) _ MySQL

Source: Internet
Author: User
Using MySQL as a file system (2) bitsCN.com

Because FUSE allows you to install the file system in any strange way. Naturally, the user's ability to install the file system on the FUSE client must be limited by the permissions of the user's group. The following is an example. at the beginning, the user was denied installation because he did not have the permission to install the file system. Then, I add myself to the corresponding user group and log on again. The initial MySQLfs file system and database are empty. Using the df command, we can see that the kernel has known the installed file system. At the end of the example, the fusermount command uninstalls the FUSE file system created by the user.
$ Mkdir ~ /Mysqlfs
$ Mysqlfs-ohost = localhost-odatabase = mysqlfs ~ /Mysqlfs
* Opening logfile 'mysqlfs. log': OK
Fuse: failed to open/dev/fuse: Permission denied
$ Su-l
Root # usermod-a-G fuse ben
Root # exit
$ Exit
...
$ Id
Uid = 500 (ben) gid = 500 (ben) groups = 492 (fuse ),...
$ Mysqlfs-ohost = localhost-odatabase = mysqlfs ~ /Mysqlfs
* Opening logfile 'mysqlfs. log': OK
$ Ls-ld mysqlfs
Drwxr-xr-x 1 root 0 2008-01-24 16:24 mysqlfs
$ Df-h mysqlfs.
Filesystem Size Used Avail Use % Mounted on
Mysqlfs 0 0 0-/home/ben/mysqlfs
/Dev/sdc3 16G 4.4G 11G 31%/home
$ Ls-l mysqlfs
Total 0
$ Fusermount-u mysqlfs
Now that we have the permission, we can install MySQL as the FUSE file system. Next, let's copy some files to the MySQL database to combine them with the file system. In the following example, I copy some text files of the Project Gutenberg to MySQLfs and verify that they have the same MD5 return values as the original files when reading them. Then, I copied the Linux file tarbar to MySQLfs and wanted to see how MySQLfs handles a 44 M file.
It takes 2 seconds to back up the kernel from the/tmp directory to the/tmp Directory through the cold disk cache, and copying it to MySQLfs takes 20 seconds. to use the cache in the disk, immediately execute the above operation again. The backup in the/tmp Directory takes 0.3 seconds, while copying to MySQLfs still takes 20 seconds. This shows that write operations are the main bottleneck of MySQLfs. When reading the kernel, MySQLfs seems to cache some data, which makes the response time much faster than other tests. If your file system uses read operations frequently, MySQLfs will be an interesting choice, because the cache of MySQLfs can be used.
~] $ Cp-av/.../guten./mysqlfs/
'/.../Guten'-> './mysqlfs/guten'
'/.../Guten/alice13a.txt'-> './mysqlfs/guten/alice13a.txt'
'/.../Guten/boysw10.txt'-> './mysqlfs/guten/boysw10.txt'
'/.../Guten/dmoro11.txt'-> './mysqlfs/guten/dmoro11.txt'
~] $ Cd ~ /Mysqlfs/guten
Guten] $ ls-l
-Rw-r ----- 1 ben 153477 alice13a.txt
-Rw ---- 1 ben 48923 boysw10.txt
-Rw ---- 1 ben 259214 dmoro11.txt
Guten] $ md5sum *
135e06ad31b169065bccbf03ec7236f2 alice13a.txt
7dd30f1b37e32cdb5d21fe992bbf248d boysw10.txt
87c05f11193c0e05b3d0dec0808a0450 dmoro11.txt
Guten] $ md5sum/.../guten /*
135e06ad31b169065bccbf03ec7236f2/.../guten/alice13a.txt
7dd30f1b37e32cdb5d21fe992bbf248d/.../guten/boysw10.txt
87c05f11193c0e05b3d0dec0808a0450/.../guten/dmoro11.txt
Guten] $ cd ..
Mysqlfs] $ time cp/tmp/linux-2.6.23.tar.bz2.
Real 0m16. 278 s
User 0m0. 006 s
Sys 0m0. 531 s
Mysqlfs] $ time cat linux-2.6.23.tar.bz2>/dev/null
Real 0m0. 502 s
User 0m0. 004 s
Sys 0m0. 035 s
Mysqlfs] $ time dd if=linux-2.6.23.tar.bz2 of =/tmp/junk bs = 1024 count = 1024
1048576 bytes (1.0 MB) copied, 0.0200973 s, 52.2 MB/s

Real 0m0. 058 s
User 0m0. 003 s
Sys 0m0. 013 s
Mysqlfs] $ time dd if=linux-2.6.23.tar.bz2 of =/tmp/junk bs = 1024 count = 1024 skip = 9000
1048576 bytes (1.0 MB) copied, 0.0214207 s, 49.0 MB/s

Real 0m0. 031 s
User 0m0. 001 s
Sys 0m0. 011 s
Despite being ignored by many people, I decided to use MySQLfs in the Bonnie ++ file system. I did these tests through the virtual machine, because the performance may be linearly degraded in the virtual machine, but because the MySQL database and/tmp directory are stored on the same virtual hard disk, its performance ratio is still effective.
In the following results, you can see that when running Bonnie ++ (version 1.03a-7), the speed of MySQLfs is of/tmp/bonnie (ext3. This indicates that we do not want to use MySQLfs to directly store the Mail directory. Bonnie ++ is designed to work on local kernel file systems rather than FUSE. This positioning is very suitable for reading and writing large row files.
$/Usr/sbin/bonnie ++-d/tmp/bonnie


Version
1.03
------ Sequential Output ------ -- Sequential Input--- Random-



-Per Chr--- Block ---Rewrite--Per Chr--- Block -- Seeks --

Machine
Size K/sec % CP
/Sec % CP

V8tsrv
2G 18155
31 16726
5 13338
6 26207
46 74527
24
9840 144


------ Sequential Create ------ -------- Random Create --------


-Create -- Read ----Delete --


Files
/Sec % CP
/Sec % CP
/Sec % CP
/Sec % CP
/Sec % CP
/Sec % CP


16 24878
94 ++ 29018
99 ++



$/Usr/sbin/bonnie ++-d ~ /Mysqlfs/bonnie



Version
1.03
------ Sequential Output ------ -- Sequential Input--- Random-


-Per Chr--- Block ---Rewrite--Per Chr--- Block -- Seeks --

Machine

Size K/sec % CP
/Sec % CP

V8tsrv
2G
2615
5
1207
1
1323
1
2143
2
2363
0 138.1
0


------ Sequential Create ------ -------- Random Create --------


-Create -- Read ----Delete --


Files
/Sec % CP
/Sec % CP
/Sec % CP
/Sec % CP
/Sec % CP
/Sec % CP


16
186
2
505
1
296
2
209
2
441
1
282
2

BitsCN.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.