Skip to content

Instantly share code, notes, and snippets.

@mbacou
Last active January 2, 2017 15:45
Show Gist options
  • Save mbacou/4bfc1344da124ae93928 to your computer and use it in GitHub Desktop.
Save mbacou/4bfc1344da124ae93928 to your computer and use it in GitHub Desktop.
Benchmarking FastRWeb and OpenCPU
## Comparing execution times between OpenCPU (RApache) and FastRWeb (Rserve and HTTP).
## Same requests and same code. Note that FastRWeb is up to 13 times faster on the 2nd call.
# OpenCPU: summarize 2 layers across districts for the whole of SSA, return json of summary table
# and then json of all pixel values for mapping
$ time curl http://127.0.0.1/ocpu/library/hcapi3/R/getLayer/json \
-d '{"var" : ["whea_h", "AEZ16_CLAS"], "by" : "ADM2_NAME_ALT"}' -X POST -H "Content-Type:application/json"
[...]
{
"ADM2_NAME_ALT": "Zvishavane",
"whea_h": 13,
"AEZ16_CLAS": "Tropic - warm / semiarid"
},
{
"ADM2_NAME_ALT": "buffer gridcell",
"whea_h": 0
}
]
real 0m5.993s
user 0m0.015s
sys 0m0.020s
# FastRWeb: same request as above (note that FastRWeb serializes a bit differently, but shouldn't matter)
$ time curl http://hcapi.harvestchoice.org/v2.0/core -d 'varCode=whea_h|AEZ16_CLAS&by=ADM2_NAME_ALT' -X POST
{"ColumnList":[{"ColumnCode":"ADM2_NAME_ALT","ColumnName":"Adm-2 Name (GAUL, 2008 mod.)",
"ColumnDesc":"Second-level administrative boundaries based on GAUL 2008 (release 2009).",
"ColumnSource":"Food and Agriculture Organization of the United Nations. FAO GEONETWORK.
Global Administrative Unit Layers (GAUL) (GeoLayer). (Latest update: 18 Feb 2014) Accessed
(20 Feb 2014). URI: http://data.fao.org/ref/f7e7adb0-88fd-11da-a88f-000d939bc5d8.html?version=1.0"},
{"ColumnCode":"AEZ16_CLAS","ColumnName":"AEZ-16","ColumnDesc":"Agro-Ecological Zones for sub-Saharan
Africa based on FAO/IIASA methodology (HarvestChoice/IFPRI 2010)","ColumnSource":"HarvestChoice/International
Food Policy Research Center (IFPRI), 2009."},{"ColumnCode":"whea_h","ColumnName":"Wheat area '05","ColumnDesc":
"Spatially disaggregated production statistics of circa 2000 using the Spatial Production Allocation Model (SPAM).
Values are for 5 arc-minute grid cells.","ColumnSource":"You, L., Z. Guo, J. Koo, K. Sebastian, and U. Wood-Sichra.
Spatial Production Allocation Model (SPAM) 2005 Version 1."}],
"ValueList":[["'Makhoroana","Subtropic - cool / semiarid"," 79"],["'Mamathe","Subtropic - cool / semiarid"," 37"],
["'Melikane","Tropic - cool / subhumid"," 114"],["'Meta","Subtropic - cool / subhumid"," 0"],
[...]
["National Council","Tropic - warm / semiarid"," 555"],["Zumbu","Tropic - warm / semiarid"," 22"],
["Zurmi","Tropic - warm / semiarid"," 0"],["Zuru","Tropic - warm / semiarid"," 0"],
["Zvimba","Tropic - cool / semiarid"," 3131"],["Zvishavane","Tropic - warm / semiarid"," 13"],
["buffer gridcell",null," 0"]]}
real 0m1.475s
user 0m0.017s
sys 0m0.006s
# OpenCPU: same request but returns all aggregated pixel values (for mapping purposes)
$ time curl http://127.0.0.1/ocpu/library/hcapi3/R/getLayer \
-d '{"var" : ["whea_h", "AEZ16_CLAS"], "by" : "ADM2_NAME_ALT", "collapse" : false}' \
-X POST -H "Content-Type:application/json"
/ocpu/tmp/x0677004d8e/R/.val
/ocpu/tmp/x0677004d8e/messages
/ocpu/tmp/x0677004d8e/stdout
/ocpu/tmp/x0677004d8e/warnings
/ocpu/tmp/x0677004d8e/source
/ocpu/tmp/x0677004d8e/console
/ocpu/tmp/x0677004d8e/info
/ocpu/tmp/x0677004d8e/files/DESCRIPTION
real 0m6.283s
user 0m0.016s
sys 0m0.010s
# FastRWeb: same request as above (but csv format instead of json so it doesn't print to console)
$ time curl http://hcapi.harvestchoice.org/v2.0/core \
-d 'varCode=whea_h|AEZ16_CLAS&by=ADM2_NAME_ALT&format=csv&collapse=FALSE' -X POST -o test.zip
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 68 0 1508 --:--:-- --:--:-- --:--:-- 1508
100 1427k 100 1427k 0 68 4187k 199 --:--:-- --:--:-- --:--:-- 4838k
real 0m0.365s
user 0m0.015s
sys 0m0.012s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment