问题
I'm trying to write a little tool for myself that would integrate with Hudson build server. The current roadblock that I've hit is performance. I'd like to do a simple thing like have a list of all jobs and the times of last successful build. The hudson API provides this information, but I either have to query everything at depth=2
or query each job individually (there's 150 of them currently). Even with exclude
either approach takes over half a minute. This is unacceptable for a UI that should be snappy. I'd need this time to be below 1s, preferably below 0.5s.
The current solution that I've come up with is doing some heavy caching on client side. Build data doesn't change, so that makes things a lot easier. But it's still a lot of coding.
Is there perhaps another way to fetch this info quickly? Perhaps there is a plugin which caches all data and enhances API speed? Note that the tool will normally NOT have access to HUDSON_HOME.
回答1:
Using the tree
query parameter is much, much faster than querying at depth=2
. According to the Hudson built-in API documentation (see Controlling the amount of data you fetch under http://hudson/api/), tree
is more efficient than exclude because the server doesn't generate and then discard data.
I think the following URL will work for the query in your question:
http://hudson/api/xml?tree=jobs[name,lastSuccessfulBuild[number,url,timestamp]]
On my system with 40-ish jobs:
$ time curl "http://hudson/api/xml?tree=jobs\[name,lastSuccessfulBuild\[number,url,timestamp\]\]"
<hudson><job><name>Example Windows build</name>
<lastSuccessfulBuild><number>7</number>
<timestamp>1264806194000</timestamp>
...lots of unformatted XML...
real 0m0.166s
user 0m0.062s
sys 0m0.093s
来源:https://stackoverflow.com/questions/4722345/how-to-get-a-better-performance-from-hudson-ci-api