Browse Source

Add Amber framework. (#2922)

* Add Amber framework.

* Fix Exception: A Int64 was expected.

* Remove debug line pp world.

* Update Amber.

Update Granite::ORM.
Add shard.lock
Add Amber logo.
Add content type constants to controller.
Remove versions in shard.yml (now uses shard.lock).
Remove dev comment on database.yml

* Execute one process per core.
Faustino Aguilar 8 years ago
parent
commit
247c7989ca

+ 1 - 0
.travis.yml

@@ -36,6 +36,7 @@ env:
     - "TESTDIR=Clojure/macchiato"
     - "TESTDIR=Clojure/pedestal"
     - "TESTDIR=Clojure/aleph"
+    - "TESTDIR=Crystal/amber"
     - "TESTDIR=Crystal/crystal"
     - "TESTDIR=Crystal/kemal"
     - "TESTDIR=Crystal/kemalyst"

+ 10 - 0
frameworks/Crystal/amber/.gitignore

@@ -0,0 +1,10 @@
+/doc/
+/lib/
+/.crystal/
+/.shards/
+/.vscode/
+/spec/
+/db/
+.env
+amber
+!shard.lock

+ 21 - 0
frameworks/Crystal/amber/LICENSE

@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2017
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.

+ 24 - 0
frameworks/Crystal/amber/README.md

@@ -0,0 +1,24 @@
+# Welcome to Amber
+
+This is the [Amber](https://www.ambercr.io) test of the Framework Benchmarks.
+
+[![Amber logo](https://i.imgur.com/NEodgHV.png)](https://www.ambercr.io)
+
+**Amber** is a web application framework written in [Crystal](http://www.crystal-lang.org) inspired by Kemal, Rails, Phoenix and other popular application frameworks.
+
+The purpose of Amber is not to create yet another framework, but to take advantage of the beautiful Crystal language capabilities and provide engineers an efficient, cohesive, and well maintain web framework for the crystal community that embraces the language philosophies, conventions, and guides.
+
+Amber Crystal borrows concepts that already have been battle tested, successful, and embrace new concepts through team and community collaboration and analysis, that aligns with Crystal philosophies.
+
+## Contributors
+
+- [eliasjpr](https://github.com/eliasjpr) Elias Perez - Maintainer
+- [fridgerator](https://github.com/fridgerator) Nick Franken - Maintainer
+- [elorest](https://github.com/elorest) Isaac Sloan - Maintainer
+- [drujensen](https://github.com/drujensen) Dru Jensen - Maintainer
+- [bew](https://github.com/bew) Benoit de Chezelles - Member
+- [faustinoaq](https://github.com/faustinoaq) Faustino Aguilar - Contributor
+
+## License
+
+This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

+ 29 - 0
frameworks/Crystal/amber/benchmark_config.json

@@ -0,0 +1,29 @@
+{
+  "framework": "amber",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "json_url": "/json",
+      "db_url": "/db",
+      "query_url": "/queries?queries=",
+      "fortune_url": "/fortunes",
+      "update_url": "/updates?queries=",
+      "plaintext_url": "/plaintext",
+      "port": 3000,
+      "approach": "Realistic",
+      "classification": "Fullstack",
+      "database": "Postgres",
+      "framework": "Amber",
+      "language": "Crystal",
+      "flavor": "None",
+      "orm": "Full",
+      "platform": "None",
+      "webserver": "None",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "Amber (MVC, Postgres)",
+      "notes": "",
+      "versus": "kemal"
+    }
+  }]
+}

+ 5 - 0
frameworks/Crystal/amber/config/application.cr

@@ -0,0 +1,5 @@
+Amber::Server.instance.config do |app|
+  app.name = "Amber web application."
+  app.port = 3000
+  app.env = "production"
+end

+ 2 - 0
frameworks/Crystal/amber/config/database.yml

@@ -0,0 +1,2 @@
+pg:
+  database: postgres://benchmarkdbuser:benchmarkdbpass@TFB-database/hello_world

+ 10 - 0
frameworks/Crystal/amber/config/routes.cr

@@ -0,0 +1,10 @@
+Amber::Server.instance.config do |app|
+  routes :web do
+    get "/plaintext", BenchmarkController, :plaintext
+    get "/json", BenchmarkController, :json
+    get "/db", BenchmarkController, :db
+    get "/queries", BenchmarkController, :queries
+    get "/updates", BenchmarkController, :updates
+    get "/fortunes", BenchmarkController, :fortunes
+  end
+end

+ 13 - 0
frameworks/Crystal/amber/setup.sh

@@ -0,0 +1,13 @@
+#!/bin/bash
+
+fw_depends postgresql crystal
+
+shards install --production
+
+crystal build --release --no-debug src/amber.cr
+
+for i in $(seq 1 $(nproc --all)); do
+  ./amber &
+done
+
+wait

+ 37 - 0
frameworks/Crystal/amber/shard.lock

@@ -0,0 +1,37 @@
+version: 1.0
+shards:
+  amber:
+    github: Amber-Crystal/amber
+    version: 0.1.4
+
+  db:
+    github: crystal-lang/crystal-db
+    version: 0.4.2
+
+  granite_orm:
+    github: Amber-Crystal/granite-orm
+    version: 0.6.3
+
+  kemalyst-validators:
+    github: kemalyst/kemalyst-validators
+    version: 0.2.0
+
+  kilt:
+    github: jeromegn/kilt
+    version: 0.3.3
+
+  pg:
+    github: will/crystal-pg
+    version: 0.13.3
+
+  radix:
+    github: luislavena/radix
+    commit: 211418416adba540b594af2260e1b5d0c8877c9e
+
+  redis:
+    github: stefanwille/crystal-redis
+    version: 1.8.0
+
+  slang:
+    github: jeromegn/slang
+    commit: b817c89c7e5ae39562710c0d6c7f42cee685e14f

+ 17 - 0
frameworks/Crystal/amber/shard.yml

@@ -0,0 +1,17 @@
+name: amber
+version: 0.1.0
+
+authors:
+  - Amber <[email protected]>
+
+license: MIT
+
+dependencies:
+  amber:
+    github: Amber-Crystal/amber 
+
+  granite_orm:
+    github: Amber-Crystal/granite-orm
+
+  pg:
+    github: will/crystal-pg

+ 8 - 0
frameworks/Crystal/amber/src/amber.cr

@@ -0,0 +1,8 @@
+require "amber"
+
+require "./controllers/**"
+require "./models/**"
+require "./views/**"
+require "../config/*"
+
+Amber::Server.instance.run

+ 78 - 0
frameworks/Crystal/amber/src/controllers/benchmark_controller.cr

@@ -0,0 +1,78 @@
+class BenchmarkController < Amber::Controller::Base
+  LAYOUT     = "main.ecr"
+  HTML_UTF8  = "text/html; charset=UTF-8"
+  JSON       = "application/json"
+  TEXT_PLAIN = "text/plain"
+  ID_MAXIMUM = 10_000
+
+  def initialize(@context)
+    super(@context)
+    response.headers["Server"] = "Amber"
+    response.headers["Date"] = Time.now.to_s
+  end
+
+  def plaintext
+    response.content_type = TEXT_PLAIN
+    "Hello, World!"
+  end
+
+  def json
+    response.content_type = JSON
+    results = {message: "Hello, World!"}
+    results.to_json
+  end
+
+  def db
+    response.content_type = JSON
+    results = {} of Symbol => Int32
+    if world = World.find rand(1..ID_MAXIMUM)
+      results = {id: world.id, randomNumber: world.randomNumber}
+    end
+    results.to_json
+  end
+
+  def queries
+    response.content_type = JSON
+    queries = params["queries"]
+    queries = queries.to_i? || 1
+    queries = queries.clamp(1..500)
+
+    results = (1..queries).map do
+      if world = World.find rand(1..ID_MAXIMUM)
+        {id: world.id, randomNumber: world.randomNumber}
+      end
+    end
+
+    results.to_json
+  end
+
+  def updates
+    response.content_type = JSON
+    queries = params["queries"]
+    queries = queries.to_i? || 1
+    queries = queries.clamp(1..500)
+
+    results = (1..queries).map do
+      if world = World.find rand(1..ID_MAXIMUM)
+        world.randomNumber = rand(1..ID_MAXIMUM)
+        world.save
+        {id: world.id, randomNumber: world.randomNumber}
+      end
+    end
+
+    results.to_json
+  end
+
+  def fortunes
+    response.content_type = HTML_UTF8
+    fortune = Fortune.new
+    fortune.id = 0
+    fortune.message = "Additional fortune added at request time."
+
+    fortunes = Fortune.all
+    fortunes << fortune
+    fortunes.sort_by! { |fortune| fortune.message || "" }
+
+    render("fortune/index.ecr")
+  end
+end

+ 9 - 0
frameworks/Crystal/amber/src/models/fortune.cr

@@ -0,0 +1,9 @@
+require "granite_orm/adapter/pg"
+
+class Fortune < Granite::ORM
+  adapter pg
+
+  table_name fortune
+  primary id : Int32
+  field message : String
+end

+ 9 - 0
frameworks/Crystal/amber/src/models/world.cr

@@ -0,0 +1,9 @@
+require "granite_orm/adapter/pg"
+
+class World < Granite::ORM
+  adapter pg
+
+  table_name world
+  primary id : Int32
+  field randomNumber : Int32
+end

+ 12 - 0
frameworks/Crystal/amber/src/views/fortune/index.ecr

@@ -0,0 +1,12 @@
+<table>
+  <tr>
+  <th>id</th>
+  <th>message</th>
+  </tr>
+  <% fortunes.each do |fortune| %>
+    <tr>
+    <td><%= fortune.id %></td>
+    <td><%= HTML.escape(fortune.message || "") %></td>
+    </tr>
+  <% end %>
+</table>

+ 9 - 0
frameworks/Crystal/amber/src/views/layouts/main.ecr

@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+<head>
+	<title>Fortunes</title>
+</head>
+<body>
+  <%= content %>
+</body>
+</html>