0

I've verified that the input files and the code is exactly the same when I run Heroku locally and Heroku on the web. I checked and checked and checked again because I couldn't believe the results.

When I run cprofile locally, I get this:

PATH: '/array_summary/'
         2830886 function calls (2804702 primitive calls) in 2.710 seconds

   Ordered by: internal time, call count
   List reduced from 1530 to 30 due to restriction <30>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
   586965    0.773    0.000    1.009    0.000 /home/redacted/graph_node_store.py:23(distance_squared)
     7444    0.409    0.000    1.537    0.000 /home/redacted/graph_node_store.py:28(find_coordinate)
  1185414    0.238    0.000    0.238    0.000 /home/redacted/subarray_graph.py:64(coordinate)

When I run cprofile on the web, I get this:

 PATH: '/array_summary/' 
           67343081 function calls (67255889 primitive calls) in 128.422 seconds 

     Ordered by: internal time, call count 
     List reduced from 1439 to 30 due to restriction <30> 
     ncalls  tottime  percall  cumtime  percall filename:lineno(function) 
   13485728   35.795    0.000   54.904    0.000 /app/redacted/graph_node_store.py:23(distance_squared) 
   28610118   20.720    0.000   20.720    0.000 /app/redacted/graph_node.py:21(coordinate) 
      10049   17.080    0.002   99.673    0.010 /app/redacted/graph_node_store.py:28(find_coordinate) 

The total function calls increase from 2.8m to 67m (23x), and the distance checks increase from 0.6m to 13m (22x).

What could possibly be causing this? I'm completely out of ideas.

S. J.
  • 1,106
  • 1
  • 10
  • 23
  • Have you tried following the call chain upwards to find out the caller of each function, and the caller of that, and the caller of _that_? – John Gordon May 18 '17 at 19:27
  • How, exactly, do you "run Heroku locally" and "Heroku on the web"? – John Gordon May 18 '17 at 19:29
  • @JohnGordon `brew install heroku` and it emulates the way heroku runs the application on the web. At least, that's what I understand. I haven't printed out callstacks for each of those function calls, but `distance_squared` is only called from one function, which is only called from one function, etc. I'm dumbfounded why the numbers can be so completely different, though. Any thoughts? – S. J. May 18 '17 at 19:33
  • Does your web server automatically start many instances of your app, in anticipation of heavy traffic? – John Gordon May 18 '17 at 21:42
  • @JohnGordon From my understanding, no, it's on demand. That could account for more modules being loaded, etc, and more overall function calls, but my `distance_squared` function should still be called the exact same number of times for the same input file. – S. J. May 18 '17 at 22:56

0 Answers0