Tutorial to speed up your project with Python settings Tmpfs

Source: Internet
Author: User
It takes a lot of time to test my current project. Now that you have more than one GB of free memory, why not let it play? TMPFS can speed up the execution of tests by keeping the file system in large memory.

But the advantage is also disadvantage, TMPFS only save the result in memory, so you have to write your own script to write the results back to disk for retention. And these scripts must be well written and executed, or they will lose some or all of their work.

A common approach is to work directly in the Tmpfs folder and then back up the work to a folder on disk. When your machine starts, you recover the Tmpfs folder from that backup folder. Synchronize TMPFS folders and disk folders with Cron after startup.


I found this setting to be a bit more complicated and error prone. At the start, or for Crom, I never really believed. Now I'm using a much simpler setup without cron at all.

Running a single test on my machine, using the IDE and publishing it on a Web server, is usually a reasonable performance, and it takes a lot of time to run all the tests.

I found the best place to set up a workspace on disk and synchronize with TMPFS running all tests in the/dev/shmand directory. This is more or less a change in my setup and eliminates the possibility of loose work, just because I'm too junk in the right settings.


The result of performance improvement is reasonable:

$ nosetests && run_tests.py ......................................................................................................................... ......................................................................................................................... ...----------------------------------------------------------------------Ran 248 tests in 107.070s OK ......................................................................................................................... ......................................................................................................................... ...----------------------------------------------------------------------Ran 248 tests in 19.423s OK

Now it's 5 times times faster than the original.

Using Python to set up is simple:

#!/bin/bash-e work=src/pylog=$ (pwd)/test.logtarget=$ (Hg root) shadow=/dev/shm/shadow/$TARGET date > $LOGmkdir-P $ SHADOW CD $SHADOWrsync--update--delete--exclude= ". *"--exclude=env--archive $TARGET. if [!-D ENV]then  virtualenv envfi. Env/bin/activate CD $WORKpython setup.py develop >> $LOGnosetests $* | Tee-a $LOGexit ${pipestatus[0]}

I just need to repeat the synchronization to the/DEV/SHM directory, set up the test environment (VIRTUALENV and Python setup. PY) and run Test (nosetests).

A single test can still be run from the command line in the Tmpfs folder. You can also kick this away from your IDE, but you will lose your ability to run and debug your tests. As I said before, I don't need this right now.

I wish I could use this workaround for TMPFS to help you build a faster development environment without having to suffer from all the scripting headaches.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.