ncache
-
Upload
guestaeef50 -
Category
Technology
-
view
2.207 -
download
0
description
Transcript of ncache
![Page 1: ncache](https://reader033.fdocuments.us/reader033/viewer/2022061218/54b79f044a795998738b4619/html5/thumbnails/1.jpg)
NCACHE
• The fast web cache server base on nginx
• Use aio sendfile and epoll modules
• The self sort share mem hash index
• High performance and large storage
• Low cpu cost and low iowait
• Record lock instead of process lock
• Without http headers cache
![Page 2: ncache](https://reader033.fdocuments.us/reader033/viewer/2022061218/54b79f044a795998738b4619/html5/thumbnails/2.jpg)
OVERVIEWF5
NGINX PROXY
NCACHE
BACKEND BACKEND BACKEND
![Page 3: ncache](https://reader033.fdocuments.us/reader033/viewer/2022061218/54b79f044a795998738b4619/html5/thumbnails/3.jpg)
STRUCTURE
Be proxy
hash index
Init by Ngx master process when nginx is start on
Ngx worker process Ngx worker process
Disk Files
Read / write by file system or raw dev
Backend server Backend server
Backend server
Body filter
Get the proxy content and save into the disk by aio
![Page 4: ncache](https://reader033.fdocuments.us/reader033/viewer/2022061218/54b79f044a795998738b4619/html5/thumbnails/4.jpg)
Logic Diagram
Request Request
Find cache in indexfound
Not found
Timeout?
not
yes
Sendfile output
Proxy backend
Body filterWritev output
Aiowrite fresh index
![Page 5: ncache](https://reader033.fdocuments.us/reader033/viewer/2022061218/54b79f044a795998738b4619/html5/thumbnails/5.jpg)
The self sort share mem hash index
2(5)
3(4)
First floor of hash index
List to solve the conflict of the hash
Hash_malloc
1(6)
Index[1]+2 = 7
1(6)
3(4)
2(7)
Top:0
16777216
33554432
If arrived at the bottom of the share memory then ncache will return to the 16777216 point and find which can be reused
![Page 6: ncache](https://reader033.fdocuments.us/reader033/viewer/2022061218/54b79f044a795998738b4619/html5/thumbnails/6.jpg)
Record lock
Mmapauto sync
Mem index Sync file
Worker process
Worker process
Read
Write
Worker process
Do not need to lock any worker processor request
cause wait
not cause wait
not cause wait
![Page 7: ncache](https://reader033.fdocuments.us/reader033/viewer/2022061218/54b79f044a795998738b4619/html5/thumbnails/7.jpg)
Performance between SQUID 1
0. 00
5. 00
10. 00
15. 00
20. 00
25. 00
0:10:01
0:40:01
1:10:01
1:40:02
2:10:01
2:40:01
3:10:01
3:40:01
4:10:01
4:40:01
5:10:01
5:40:01
6:10:01
6:40:01
7:10:01
7:40:01
8:10:01
8:40:01
9:10:01
9:40:01
10:10:01
10:40:01
11:10:01
11:40:01
12:10:01
12:40:01
13:10:01
13:40:02
14:10:01
14:40:01
15:10:01
15:40:01
16:10:01
16:40:01
17:10:01
17:40:01
18:10:01
18:40:01
19:10:01
19:40:01
20:10:01
20:40:01
21:10:01
21:40:01
22:10:01
22:40:01
23:10:01
23:40:01
0. 001. 002. 003. 004. 005. 006. 007. 008. 009. 0010. 00
0:10:01
0:40:01
1:10:01
1:40:02
2:10:01
2:40:01
3:10:01
3:40:01
4:10:01
4:40:01
5:10:01
5:40:01
6:10:01
6:40:01
7:10:01
7:40:01
8:10:01
8:40:01
9:10:01
9:40:01
10:10:01
10:40:01
11:10:01
11:40:01
12:10:01
12:40:01
13:10:01
13:40:02
14:10:01
14:40:01
15:10:01
15:40:01
16:10:01
16:40:01
17:10:01
17:40:01
18:10:01
18:40:01
19:10:01
19:40:01
20:10:01
20:40:01
21:10:01
21:40:01
22:10:01
22:40:01
23:10:01
23:40:01
First: cpu last: io Blue is ncache
![Page 8: ncache](https://reader033.fdocuments.us/reader033/viewer/2022061218/54b79f044a795998738b4619/html5/thumbnails/8.jpg)
Performance between SQUID 2
0. 050. 0100. 0150. 0200. 0250. 0300. 0350. 0400. 0450. 0500. 0
1 57
113
169
225
281
337
393
449
505
561
617
673
729
785
841
897
953
0. 050. 0100. 0150. 0200. 0250. 0300. 0350. 0400. 0450. 0500. 0
1 57
113
169
225
281
337
393
449
505
561
617
673
729
785
841
897
953
SQUID
NCACHE
![Page 9: ncache](https://reader033.fdocuments.us/reader033/viewer/2022061218/54b79f044a795998738b4619/html5/thumbnails/9.jpg)
Future
• The aio_sendfile function
• Compress share memory hash index
• Memory cache the hottest data
• Raw device read and write
• Distribute storage system
• Aio queue with lio_listio function
![Page 10: ncache](https://reader033.fdocuments.us/reader033/viewer/2022061218/54b79f044a795998738b4619/html5/thumbnails/10.jpg)
The end
• Google code:– http://code.google.com/p/ncache/
• Nginx wiki:– http://wiki.codemongers.com/
• Our mail:– [email protected]– [email protected]