Tuesday, January 29, 2013

scala + lift + json

So since I really really really dislike soap and Java, I decided to play a bit more with scala and rest based web services. Basically parse some JSON strings with scala.

Now after browsing countless articles and remembering the JSON structure, I finally found the 'lift-json' project, which simplifies my live as busy developer a bit.

How to parse JSON with scala?


package edu.ucdavis.fiehnlab.alchemy.core.communication.services.reader
import edu.ucdavis.fiehnlab.alchemy.core.process.types.LibrarySpectra
import net.liftweb.json.parse
import net.liftweb.json.DefaultFormats
/**
 * connects to the alchemy webservice and fetches all registered co
 */
class WebserviceLibraryReader {

  /**
   * internal converter class to simplify things
   */
  case class JsonCompound(name: String, inchikey: String, retentiontime: Double, theoretical: Double, massspectra: String)

  case class CompoundWapper(compound: Array[JsonCompound])

  implicit val formats = DefaultFormats

  /**
   * downloads the compounds for the given URL and returns it as a set of library spectra
   */
  def fetchCompounds(url: String): Set[LibrarySpectra] = {

    val compounds: CompoundWapper = parse("""
        
        {"compound":[{"name":"test","inchikey":"ADVPTQAUNPRNPO-UHFFFAOYSA-N","retentiontime":11111,"theoretical":11,"massspectra":"111:1 112:2 113:3"},{"name":"test","inchikey":"ADVPTQAUNPRNPO-UHFFFAOYSA-N","retentiontime":11111,"theoretical":11,"massspectra":"111:1 112:2 113:3"}]}
        
        """).extract[CompoundWapper]

    compounds.compound.foreach { x: JsonCompound =>
      println(x)
    }
    
    
    null
  }

}

object WebserviceLibraryReader {

  def main(ars: Array[String]) = {
    println(new WebserviceLibraryReader().fetchCompounds("http://localhost:8080/alchemy-admin/services/queryAllCompoundsForMethod/test"))
  }
}

The complete tutorial can be found here

Thursday, January 24, 2013

using ssd's in a raid0 over 4 drives.

Recently I played a bit more with ssd's, since frankly they are getting affordable enough to use as scratch drives for our new software product.

Basically I was wondering, if a raid0 over 4 ssd's is fast enough for us, or if I should use a PCI-Express card.



root@****:/mnt/luna/scratch/gert# dd if=/dev/zero of=/mnt/scratch/bs.img bs=8048 count=81920
81920+0 records in
81920+0 records out
659292160 bytes (659 MB) copied, 0.529044 s, 1.2 GB/s
root@****:/mnt/luna/scratch/gert# dd of=/dev/null if=/mnt/scratch/bs.img bs=8048 count=81920
81920+0 records in
81920+0 records out
659292160 bytes (659 MB) copied, 0.129838 s, 5.1 GB/s


Sure the sample size is not perfect, but for a first test I'm rather surprised by this result and looking forward, if the speed keeps up like this.