Git Product home page Git Product logo

sbt-tmpfs's Introduction

Build Status Download

sbt-tmpfs

sbt plugin that automatically "tmpfsifies" directories to speed up development.

sbt 1.0.0+. For those of you who have trouble downloading doc and src through IDEA, use reload plugins then updateClassifiers in console.

Why tmpfs?

Comparison with common specs:

Tpe Read speed Response time Power usage
ram 30GB/s 100 ns 2 - 3 w
ssd 500MB/s 0.1 ms 1 - 3 w
sas-hdd fast in raid 20+ ms 15 w

RAM is thousands of times faster than SSD. Tmpfs provides an easy way to leverage RAM. More, RAM is immune to the exertion brought by infinite compilation/clean cycles. While SSD is tolerant, developers are not. Latency Numbers Every Programmer Should Know

Why sbt-tmpfs?

sbt-tmpfs brings automation to leverage tmpfs to speedup your development.

How to use:

Note: due to #1444, make sure sbt >= 0.13.14

Mount your /tmp with tmpfs, by adding this line to your /etc/fstab if you haven't yet:

tmpfs /tmp tmpfs rw,nosuid,nodev,noatime

Reboot you pc.

Add below to project/plugins.sbt:

addSbtPlugin("com.github.cuzfrog" % "sbt-tmpfs" % "0.3.4") //for sbt 1.1 and sbt 0.13

Now, enjoy RAM speed!

(If you use sbt-revolver reStart, run compile to trigger sbt-tmpfs first.)

Detail and Configuration:

Directory mode:

There are 2 strategies to use tmpfs:

  • Symlink into existing tmpfs dir. (Harder management.)
  • Directly mount the point with tmpfs. (Requires super privilege)

Symlink is the default one, since it does not require super. Default linking dirs include crossTarget and target/resolution-cache. Add more dirs to be linked:

tmpfsLinkDirectories ++= Seq(//your dirs here.)

Broken symlink will be overwrite by sbt-tmpfs. (Symlink of some dir like streams may lead to sbt error when symlink is broken after a reboot.) The base tmpfs dir where symlinks point to, by default, is /tmp, which is controlled by tmpfsLinkBaseDirectory.

When Mount mode is in use, sbt command line may require super password to execute shell command. Mount size limit key:tmpfsMountSizeLimit , shell command can also be changed by tmpfsMountCommand. Default mount point is target. Add more dirs to be mounted:

tmpfsMountDirectories ++= Seq(//your dirs here.)

In fact, Mount mode is recommended. It's easier to handle in most cases, and not likely to cause some unexpectation.

You can set below in your build.sbt.

tmpfsDirectoryMode := TmpfsDirectoryMode.Mount
onLoad in Global := {
  val insertCommand: State => State =
    (state: State) =>
      state.copy(remainingCommands = Exec(";project1/tmpfsOn;project2/tmpfsOn", None) +: state.remainingCommands)
  (onLoad in Global).value andThen insertCommand
}

Changing mode after the other has been done, will cause some minor inconsistency. For example: if target has been mounted first, tmpfsLink task may have no effect. It will realize that dirs inside target are all of tmpfs now, so it aborts linking. Fortunately, most of the inconsistency will be repaired after a reboot or clean.

Work flow:

sbt-tmpfs checks target dirs defined in key tmpfsLinkDirectories or tmpfsMountDirectories and mounts/links tmpfs when necessary.

Under Symlink mode, when user does a clean, symlinks themselves will be purged. When new symlinks are created, sbt-tmpfs deletes old dirs in tmpfs that old symlinks referenced.

Task tmpfsOn: check and link/mount when needed. Dyn-defined by mode as tmpfsLink or tmpfsMount.

Task tmpfsLink: check and link when needed. runBefore update, triggeredBy clean.

Task tmpfsMount: check and mount when needed.

Task tmpfsSyncMapping: sync mapped dirs, triggered by above.

On initializing, sbt-tmpfs will try to clean dead(broken) symlinks, possibly created last time.

Map and sync dirs:

Sometimes, we want to speedup some dirs while wanting to preserve them on disk, like node_modules, we can map these dirs.

tmpfsMappingDirectories := Map(
  sourceDir -> Seq(destDir) //sourceDir is somewhere on disk.
)

sbt-tmpfs will link/mount destDir with tmpfs, if they are not an active symlink or already of tmpfs, and automatically does one-way-synchronization: from source to destination.

There is an Interesting Test: sbt.IO-vs-rsync-vs-cp about choosing which method to do the sync.

destDirs are added to cleanKeepFiles by sbt-tmpfs automatically (but only direct children of target take effect).

Debug info:

sbt-tmpfs has thorough debug log. Set log level to debug in tasks respectively:

logLevel in tmpfsOn := Level.Debug
logLevel in tmpfsLink := Level.Debug
logLevel in tmpfsMount := Level.Debug
logLevel in tmpfsSyncMapping := Level.Debug

About

Author: Cause Chung ([email protected])

License: Apache License Version 2.0

sbt-tmpfs's People

Contributors

xuwei-k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

xuwei-k

sbt-tmpfs's Issues

How to verify compilation speed up?

Hi, I just found this project and immediately decided to try.
I cloned this project https://github.com/unibas-gravis/scalismo, built it to download all dependencies.
Then I rebuilt it with this command:

$ sbt clean compile

This took 34 seconds on my machine.
Then I set up tmpfs at /tmp, added sbt-tmpfs into project/plugins.sbt and ran this command again.

$ sbt clean compile

This gave 34 seconds again.
I verified that compiler output is inside /tmp:

$ ls /tmp/sbttmpfs/
sbt_27b42856 sbt_bdebd5f4

So, should this plugin boost compilations from scratch or only incremental ones?
How to measure the boost?

How to disable tmpfs compilation?

Things tried

  1. sbt clean
  2. Disabling sbt-tmpfs plugin
  3. rm -rf **/target
  4. sbt clean

But still

$ sbt run
...
$ sbt run
...
$ du -sBM /tmp/* | sort -n
...
150M	/tmp/sbt_65105098
150M	/tmp/sbt_bd138339

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.