GAE的数据库测试:Java性能比Python慢5倍!
2009 6 17 05:34 PM 3312次查看
分类:Google App Engine 标签:Google App Engine, 性能
测试方法是创建100个只含一个字符串的实体,保存到数据库。
再从数据库获取100个,然后删除这些实体。
你可以在这测试(不过别测太多了,CPU消耗太大了):
Java:http://java.latest.gaejava.appspot.com
Python:http://python.latest.gaejava.appspot.com
测试结果:
Java:
添加:
Time of save 1 entity: 54ms
Time of create 100 entities: 0ms
Time of save 100 entities: 7765ms
Time of save 1 entity: 52ms
Time of create 100 entities: 0ms
Time of save 100 entities: 7059ms
Time of save 1 entity: 61ms
Time of create 100 entities: 0ms
Time of save 100 entities: 7384ms
更新:
Time of fetch 1 entity: 222ms
Time of update 1 entity: 25ms
Time of fetch 100 entities: 40ms
Time of update 100 entities: 7098ms
Time of fetch 1 entity: 33ms
Time of update 1 entity: 25ms
Time of fetch 100 entities: 35ms
Time of update 100 entities: 8038ms
Time of fetch 1 entity: 14ms
Time of update 1 entity: 24ms
Time of fetch 100 entities: 34ms
Time of update 100 entities: 8425ms
删除:
Time of fetch 1 entity: 16ms
Time of delete 1 entity: 82ms
Time of fetch 100 entities: 36ms
Time of delete 100 entities: 7655ms
Time of fetch 1 entity: 93ms
Time of delete 1 entity: 104ms
Time of fetch 100 entities: 45ms
Time of delete 100 entities: 9825ms
Time of fetch 1 entity: 176ms
Time of delete 1 entity: 98ms
Time of fetch 100 entities: 60ms
Time of delete 100 entities: 7784ms
后台记录:
06-17 07:34AM 51.575 /del 200 8145ms 7970cpu_ms 6823api_cpu_ms 0kb java.latest.gaejava.appspot.com Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/531.0 (KHTML, like Gecko) Chrome/3.0.187.1 Safari/531.0,gzip(gfe)
06-17 07:34AM 36.326 /del 200 10094ms 8083cpu_ms 6823api_cpu_ms 0kb java.latest.gaejava.appspot.com Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/531.0 (KHTML, like Gecko) Chrome/3.0.187.1 Safari/531.0,gzip(gfe)
06-17 07:34AM 21.466 /del 200 7819ms 7942cpu_ms 6823api_cpu_ms 0kb java.latest.gaejava.appspot.com Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/531.0 (KHTML, like Gecko) Chrome/3.0.187.1 Safari/531.0,gzip(gfe)
06-17 07:34AM 02.319 /update 200 8519ms 13189cpu_ms 11929api_cpu_ms 0kb java.latest.gaejava.appspot.com Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/531.0 (KHTML, like Gecko) Chrome/3.0.187.1 Safari/531.0,gzip(gfe)
06-17 07:33AM 48.282 /update 200 8159ms 13105cpu_ms 11929api_cpu_ms 0kb java.latest.gaejava.appspot.com Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/531.0 (KHTML, like Gecko) Chrome/3.0.187.1 Safari/531.0,gzip(gfe)
06-17 07:33AM 35.099 /update 200 7426ms 13664cpu_ms 11929api_cpu_ms 0kb java.latest.gaejava.appspot.com Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/531.0 (KHTML, like Gecko) Chrome/3.0.187.1 Safari/531.0,gzip(gfe)
06-17 07:33AM 20.908 /add 200 7476ms 10684cpu_ms 9453api_cpu_ms 0kb java.latest.gaejava.appspot.com Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/531.0 (KHTML, like Gecko) Chrome/3.0.187.1 Safari/531.0,gzip(gfe)
06-17 07:33AM 07.749 /add 200 7146ms 10684cpu_ms 9453api_cpu_ms 0kb java.latest.gaejava.appspot.com Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/531.0 (KHTML, like Gecko) Chrome/3.0.187.1 Safari/531.0,gzip(gfe)
06-17 07:32AM 49.846 /add 200 7862ms 10825cpu_ms 9453api_cpu_ms 0kb java.latest.gaejava.appspot.com Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/531.0 (KHTML, like Gecko) Chrome/3.0.187.1 Safari/531.0,gzip(gfe)
Python:
添加:可以看到Java和Python的CPU时间都是差不多的,但Python响应时间却只有Java的1/5左右。
Time of save 1 entity: 129.576921ms
Time of create 100 entities: 2.582073ms
Time of save 100 entities: 1210.234880ms
Time of save 1 entity: 54.707050ms
Time of create 100 entities: 2.454042ms
Time of save 100 entities: 1481.308937ms
Time of save 1 entity: 47.955990ms
Time of create 100 entities: 2.021074ms
Time of save 100 entities: 1310.760021ms
更新:
Time of fetch 1 entity: 388.538837ms
Time of update 1 entity: 53.938150ms
Time of fetch 100 entities: 96.820831ms
Time of update 100 entities: 1242.298126ms
Time of fetch 1 entity: 409.255028ms
Time of update 1 entity: 43.366909ms
Time of fetch 100 entities: 92.492104ms
Time of update 100 entities: 1119.529963ms
Time of fetch 1 entity: 431.589842ms
Time of update 1 entity: 37.049055ms
Time of fetch 100 entities: 76.496124ms
Time of update 100 entities: 2046.729803ms
删除:
Time of fetch 1 entity: 417.876959ms
Time of delete 1 entity: 62.140942ms
Time of fetch 100 entities: 105.495930ms
Time of delete 100 entities: 1161.437988ms
Time of fetch 1 entity: 614.541054ms
Time of delete 1 entity: 49.677849ms
Time of fetch 100 entities: 90.868950ms
Time of delete 100 entities: 1129.801989ms
Time of fetch 1 entity: 563.830853ms
Time of delete 1 entity: 66.990137ms
Time of fetch 100 entities: 188.508034ms
Time of delete 100 entities: 1076.126814ms
后台记录:
06-17 07:36AM 51.238 /del 200 1979ms 7102cpu_ms 6823api_cpu_ms 0kb python.latest.gaejava.appspot.com Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/531.0 (KHTML, like Gecko) Chrome/3.0.187.1 Safari/531.0,gzip(gfe)
06-17 07:36AM 42.483 /del 200 1896ms 6942cpu_ms 6823api_cpu_ms 0kb python.latest.gaejava.appspot.com Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/531.0 (KHTML, like Gecko) Chrome/3.0.187.1 Safari/531.0,gzip(gfe)
06-17 07:36AM 33.591 /del 200 1778ms 6962cpu_ms 6823api_cpu_ms 0kb python.latest.gaejava.appspot.com Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/531.0 (KHTML, like Gecko) Chrome/3.0.187.1 Safari/531.0,gzip(gfe)
06-17 07:36AM 16.895 /update 200 2605ms 12258cpu_ms 12034api_cpu_ms 0kb python.latest.gaejava.appspot.com Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/531.0 (KHTML, like Gecko) Chrome/3.0.187.1 Safari/531.0,gzip(gfe)
06-17 07:36AM 00.586 /update 200 1679ms 12258cpu_ms 12034api_cpu_ms 0kb python.latest.gaejava.appspot.com Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/531.0 (KHTML, like Gecko) Chrome/3.0.187.1 Safari/531.0,gzip(gfe)
06-17 07:35AM 51.585 /update 200 1789ms 12230cpu_ms 12034api_cpu_ms 0kb python.latest.gaejava.appspot.com Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/531.0 (KHTML, like Gecko) Chrome/3.0.187.1 Safari/531.0,gzip(gfe)
06-17 07:35AM 41.851 /add 200 1367ms 9584cpu_ms 9453api_cpu_ms 0kb python.latest.gaejava.appspot.com Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/531.0 (KHTML, like Gecko) Chrome/3.0.187.1 Safari/531.0,gzip(gfe)
06-17 07:35AM 34.596 /add 200 1549ms 9621cpu_ms 9453api_cpu_ms 0kb python.latest.gaejava.appspot.com Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/531.0 (KHTML, like Gecko) Chrome/3.0.187.1 Safari/531.0,gzip(gfe)
06-17 07:35AM 26.595 /add 200 1458ms 9649cpu_ms 9453api_cpu_ms 0kb python.latest.gaejava.appspot.com Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/531.0 (KHTML, like Gecko) Chrome/3.0.187.1 Safari/531.0,gzip(gfe)
顺带一提,我只测试了JDO,其他的懒得测了。
顺便比较一下代码:
Java:
8.52 MB (8,937,261 字节)
11文件夹
30文件
去掉lib文件夹:
124 KB (127,573 字节)
10文件夹
23文件
247行代码(不包括自动生成的代码)
Python:
4.36 KB (4,468 字节)
1文件夹
4文件
127行代码
最后放上测试代码,Java的war\WEB-INF\lib文件夹已删除,请自己添加。
向下滚动可载入更多评论,或者点这里禁止自动加载。