I have a node.js canvas app that queries salesforce for accounts and there are only 10 of them , but for some reason it takes about 4-5 seconds before the response comes back. I have used both nforce and node-salesforce modules for this and both are taking the same time.

Example code:


var query = 'SELECT Name, Id FROM Account';
org.query(query, auth, callback(err, resp) {
  if(!err) console.log(resp)

and node-salesforce

conn.query("SELECT Id, Name FROM Account", function(err, result) {
  if (!err) { return console.log(result); }

The auth details are already recorded, so no login is required.

I have tried calling other APIs and again it takes 4-5 seconds.


  • What happens if you try the same request from a Java SOAP application? The salesforce API is often very slow and 5 seconds is not unheard of, but from my experience most requests return in under a second. – James Davies Feb 7 '13 at 2:35
  • 1
    I just tried the same query in a DE org with 12 Accounts using curl: time curl -H 'X-PrettyPrint: 1' -H 'Authorization: Bearer ACCESS_TOKEN' https://na15.salesforce.com/services/data/v26.0/query/?q=SELECT+Name,Id+FROM+Account. Over 10 runs, the average time was about 0.5s. How long does curl take for you? – metadaddy Feb 7 '13 at 5:49
  • thanks guys, I have run curl and the initial request takes 5 seconds, but subsequent ones are sub second, will try to git clone one of the example apps and do some further testing on this. – rumdumdum Feb 7 '13 at 12:29
  • 1
    I'm the author of nforce so hopefully I can help. I've never seen responses that slow before. Is it possible that the instance you were on had some sort of performance degradation at the time of testing? I get roughly the same response times when I curl vs using conn.query(). – Kevin O'Hara Mar 7 '13 at 13:51
  • I've seen this behavior when there is a large volume of records, even if a given user can't see more than a few of them. Could have to do with rollup summaries of large volumes of records too. – Tom Gersic Mar 7 '13 at 21:22

So I just ran some benchmarks in nforce version 0.3.0. I now see what you see. It seems to me that the initial request to the API after an extended period of API inactivity returns a slower response from the platform. I'm not exactly sure why this happens, but all of the subsequent requests are averaging around .325s after the initial request that took > 9s! Here are some tests that I ran. The code in nforce.js is the same as your example.

λ: time node nforce.js
real    0m9.608s
user    0m0.136s
sys     0m0.023s
λ: time node nforce.js
real    0m0.324s
user    0m0.133s
sys     0m0.021s
λ: time node nforce.js
real    0m0.323s
user    0m0.137s
sys     0m0.022s
λ: time node nforce.js
real    0m0.329s
user    0m0.136s
sys     0m0.023s

Curl yielded roughly the same result.


What makes the most sense here is that the API is doing some sort of authentication caching. This is a pretty common practice. Your initial request takes a while because your token must be checked on the backend as it's not yet in the cache. After that initial request, your auth is cached at the API level for speed in subsequent requests. After a period of inactivity or after the max size of the cache is reached and yours was the least recently used (LRU caching), your access token is flushed from the cache.

  • Anything to do with a refresh token loop? – joshbirk Mar 7 '13 at 16:04
  • Nope. By design, nforce doesn't make any API requests on behalf of the user. That includes refreshes. – Kevin O'Hara Mar 7 '13 at 16:53
  • Is it possible that there is some sort of authentication caching in the API? That would explain the slow initial response and faster subsequent responses. – Kevin O'Hara Mar 7 '13 at 16:54
  • 1
    I updated to add my hypothesis as to what is happening. – Kevin O'Hara Mar 7 '13 at 17:12
  • Hey @KevinO'Hara, thanks for your input on this. Have been doing some dev work on Heroku lately and have not noticed the lag to be as bad as it was previously, will run some tests, but it does seem a bit better then before. – rumdumdum Mar 22 '13 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.