title: Why multi-threaded python program slow on ec2 micro-instance?
body: <p>I am working on a Online Judge code checker.My code uses multi-threading in python 2.7.The same program on my local machine (i core 3 RAM 4GB) evaluates about 1000 submisions in 1 minute 10 seconds. But when I run it on ec2 micro instance(about 600 MB RAM) it takes about
  40 minutes(It gets slow for some random seconds).To know the reason I broke down things.</p>
  
  <ol>
  <li><p>First this is how my evaluator works:<br></p>
  
  <ul>
  <li>I have a main program <code>worker.py</code> , which creates multiple threads</li>
  <li>The main thread pulls submissions(10 at a time) from a file(for time being) and puts them in a global queue</li>
  <li>The side threads take submisions from queue(one submission evaluated solely by one thread)</li>
  <li>After a side thread takes a submission it sends it to a function <code>compile</code>,which
      returns the executable of submission back to that thread</li>
  <li>Then the thread sends this executable to a function <code>run</code> which runs the executable
      (using sandbox with defined memory and time limits) and writes the output of the executable to file and then checks it<br>
  against    standard output</li>
  <li>After the queue gets empty the main thread again pulls 10 submissions and places them in queue
  <br><br></li>
  </ul></li>
  <li><p>The functions <code>compile</code> and <code>run</code>:      </p>
  
  <ul>
  <li>The compile function and run function save the executable and output in files(repectively) named
      like <code>&lt;thread_Name&gt;.exe</code> and <code>&lt;thread_Name&gt;.txt</code> so that every thread has its own files
      and there is no issue of overwriting.</li>
  <li>A thread goes to run function only if status from compile function was OK(the file compiled)otherwise throws compile error for
  that    submission <br><br></li>
  </ul></li>
  <li><p>Now the doubts I have:</p>
  
  <ul>
  <li>Is the problem of slow execution on ec2 due to the resources it has or due
      to multi-threading of python.In my scripts the threads to access global variables
      such as  the queue(i put locks) and <code>test.py(I dont put lock on it)</code> which in run
      function checks the output with standard output character by character(vimdiff like),
      and <code>mysandbox.py(libsandbox the sandbox)</code>
      and some other global variables.So is the slow working due to GIL of python.If it
      is so then why does it work fast on my local machine.</li>
  <li>Also for time being I give the same file <code>test.cpp(adds two numbers and prints result)</code>
      1000 times.So when I purposely make a compile error in this file and run my main
      program on ec2 it runs pretty fast.From that I deduced that the compiling and
      and running(compile and run functions) of my program take the main time,not the thread
      creation and management.</li>
  </ul></li>
  </ol>
  
  <p>I know its a vast question but any help is really appreciated(or i will have to keep bounty on it betting all my reputation :) ).</p>