Skip to content

Commit

Permalink
Clean rps sample
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumebort committed Feb 9, 2012
1 parent 83f51fb commit 9e700a9
Show file tree
Hide file tree
Showing 36 changed files with 67 additions and 66 deletions.
File renamed without changes.
5 changes: 5 additions & 0 deletions samples/scala/comet-live-monitoring/README
@@ -0,0 +1,5 @@
This app is designed to run on iPhone (but you can also load it in any modern browser).

It display live application performance data. The simplest way to load the application is running:

ab -k -c 100 -n 1000000 http://localhost:9000/load
Expand Up @@ -10,16 +10,16 @@ import scala.concurrent.stm._

object Application extends Controller {

def index = Action {
def load = Action {
SpeedOMeter.countRequest()
Ok("from your shell ab -k -c 100 -n 1000000 http://localhost:9000/")
Ok("from your shell ab -k -c 100 -n 1000000 http://localhost:9000/load")
}

def monitor = Action {
def index = Action {
Ok(views.html.monitor(Runtime.getRuntime().totalMemory()/(1024*1024)))
}

def speedMeter = Action {
def monitoring = Action {
Ok.stream(
Streams.getRequestsPerSecond >-
Streams.getCPU >-
Expand All @@ -29,7 +29,7 @@ object Application extends Controller {

def gc = Action {
Runtime.getRuntime().gc()
Ok("ok")
Ok("Done")
}
}

Expand Down Expand Up @@ -73,7 +73,6 @@ object SpeedOMeter {
}
}


def getSpeed = {
val current = java.lang.System.currentTimeMillis()
val (precedent,(count,millis)) = counter.single()
Expand Down
42 changes: 42 additions & 0 deletions samples/scala/comet-live-monitoring/app/models/CPU.java
@@ -0,0 +1,42 @@
package models;

import com.sun.management.OperatingSystemMXBean;
import java.lang.management.*;

public class CPU {

private int availableProcessors = ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors();

private long lastSystemTime = 0;
private long lastProcessCpuTime = 0;

public synchronized double getCpuUsage() {
if(lastSystemTime == 0) {
baselineCounters();
return 0;
}

long systemTime = System.nanoTime();
long processCpuTime = 0;

if(ManagementFactory.getOperatingSystemMXBean() instanceof OperatingSystemMXBean) {
processCpuTime = ((OperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean()).getProcessCpuTime();
}

double cpuUsage = (double) (processCpuTime - lastProcessCpuTime) / (systemTime - lastSystemTime);

lastSystemTime = systemTime;
lastProcessCpuTime = processCpuTime;

return cpuUsage / availableProcessors;
}

private void baselineCounters() {
lastSystemTime = System.nanoTime();

if (ManagementFactory.getOperatingSystemMXBean() instanceof OperatingSystemMXBean) {
lastProcessCpuTime = ( (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean() ).getProcessCpuTime();
}
}

}
File renamed without changes.
@@ -1,4 +1,5 @@
@(totalMemory: Long)

@main("RPS") {
<script type="text/javascript">
window.App = { };
Expand Down
File renamed without changes.
Expand Up @@ -3,9 +3,9 @@
# ~~~~

# Home page
GET / controllers.Application.index()
GET /speed-meter controllers.Application.speedMeter
GET /monitor controllers.Application.monitor
GET / controllers.Application.index
GET /load controllers.Application.load
GET /monitoring controllers.Application.monitoring
POST /gc! controllers.Application.gc

# Map static resources from the /public folder to the /assets URL path
Expand Down
Expand Up @@ -4,7 +4,7 @@ import PlayProject._

object ApplicationBuild extends Build {

val appName = "cpu"
val appName = "comet-live-monitoring"
val appVersion = "1.0"

val appDependencies = Seq(
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions samples/scala/comet-live-monitoring/project/plugins.sbt
@@ -0,0 +1,8 @@
// Comment to get more information during initialization
logLevel := Level.Warn

// The Typesafe repository contains all required dependencies
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"

// Use the Play sbt plugin for Play projects
addSbtPlugin("play" % "sbt-plugin" % Option(System.getProperty("play.version")).getOrElse("2.0"))
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Expand Up @@ -87,7 +87,7 @@

var button = $("button");
button.className = "gc";
button.innerHTML = "GARBAGE RESET";
button.innerHTML = "GARBAGE COLLECT";

button.addEventListener("click", function (evt){
evt.target.className += " touch";
Expand All @@ -105,7 +105,7 @@
document.body.appendChild(button);

var iframe = $("iframe");
iframe.src = "/speed-meter";
iframe.src = "/monitoring";
iframe.style.display = "none";

window.message = function (msg) {
Expand Down
43 changes: 0 additions & 43 deletions samples/scala/rps/app/models/CPU.java

This file was deleted.

5 changes: 0 additions & 5 deletions samples/scala/rps/app/views/index.scala.html

This file was deleted.

6 changes: 0 additions & 6 deletions samples/scala/rps/project/plugins.sbt

This file was deleted.

Binary file removed samples/scala/rps/rps-screenshot.png
Binary file not shown.

0 comments on commit 9e700a9

Please sign in to comment.