Scala会議に参加してきました「ScalaからGPUを使ってみる ScalaCL Compiler Plugin」 - chimerastのエレガント指向プログラミング日記. Scala会議に参加してきました「ScalaからGPUを使ってみる ScalaCL Compiler Plugin」 勉強会はBlogを書くところまでが勉強会です。 ということで久しぶりに書きます。 あいかわらずのLTの時間破り魔っぷりでした。 申し訳ありませんでした。 15分ぐらいのMiddle Talk的な枠が欲しいです。 LT内容は「ScalaからGPUを使ってみるScalaCL Plugin」、ScalaコードをOpenCL C言語に変換してくれるScalaCLというコンパイラプラグインの話をGPUってすごいんだよって話とともにお届けしました。 ※ ScalaCLは本当に不安定です。 Scala+ScalaCLのベンチマークコード(github) Scala+JavaCLのサンプルコード(github) Scala+OpenGL+GLSLのMikuMikuDance(github) スライドにも書きましたが、最近のグラフィックボードってすごいですね。 GPUは多数のユニット(コア)あるわけですが、それぞれのユニットで別々のプログラムを動かせるというわけではありません。 また、OpenCLの情報ですが、下の「OpenCL入門 - マルチコアCPU・GPUのための並列プログラミング -」が非常に読みやすく、背景、必要な知識が書かれていると思うので、OpenCL/GPGPUに興味のある方はぜひ買ってみてください。 ScalaCLは、Scalaが使っている人が気軽にGPUを使ってみようかと興味を持つという点では非常に良いと思います。 株式会社ユーザベースでは一緒に働いてくれる人を募集中です。 シェルのコマンドを実行する - 技術備忘録. シェルのコマンドを実行する Scalaではscala.sys.processパッケージを使うことでシェルのコマンドを実行できます。 #! /bin/sh #process.scala exec scala "$0" "$@" !
# import scala.sys.process._ import java.net.URL import java.io.File val res = (Process("ls /etc") #| Process("sort -r") #| Process("grep ^p")).lines.toList res.foreach(println) new URL(" #> new File("yahoo.html") ! > . python3.2 python2.7 python pulse protocols profile.d <title>Yahoo! Scalaでプログラムを作りました. 非同期処理でWebコンテンツをダウンロードする方法 - Groovy, Scala, F# - なんとなくな Developer のメモ. 前回(id:fits:20110925)、並列コレクション等で Web コンテンツをダウンロードする処理を実装してみましたが、今回はその非同期処理版を Groovy, Scala, F# で実装してみました。 (主な仕様は前回と同じ) Groovy の場合: GPars 非同期処理でも GPars が使えます。 GParsPool.withPool や GParsExecutorsPool.withPool 内*1で、クロージャに対して async() を実行すると非同期化されたクロージャを取得できます。
非同期化されたクロージャを実行すると Future が返り、Future に対して get() を呼び出す事で処理結果を取得します。 今回は指定の URL に接続する処理とダウンロードしてローカルファイルを作成する処理を非同期化し、全 URL を非同期で処理した後にループで 1件ずつ完了待ちするようにしてみました。 また、GParsExecutorsPool よりも GParsPool の方が速く感じたので、今回は GParsPool を使っています。 Groovy 1.8.2 async_download_web.groovy Scala の場合: 限定継続 + Actor 今回、Scala では限定継続と Actor を使って非同期処理を実装してみました。 Groovy 等と比べるとコード量は多くなりますが、継続オブジェクト(下記サンプルでは k の箇所)を Actor に渡す事で非同期処理を同期的に実装できるようになります。 下記サンプルでは、(1) 〜 (6) のような処理の流れが非同期的に実行されるようになっています。 非同期化している箇所は Groovy 版のサンプルとほぼ同じですが、ダウンロードが完了したものから処理結果を文字列出力するようになっています。 Scala 2.9.1(JavaSE 7 依存) なお、Scala 2.9.1 で限定継続を使う場合は実行時に -P:continuations:enable オプション指定が必要になります。 実行例(限定継続を有効化) scala -P:continuations:enable async_download_web.scala destdir < urls.txt async_download_web.scala.
Instance Type (Abstract type gotcha 1) In a previous post about abstract types I showed one of the benefits of using abstract types over parameterized types. Abstract Types vs Parameter. The next several posts will feature potential problems you may encounter when using Abstract Types. I should point out that abstract types are not inherently difficult to understand but they are rather different from anything you will see when you come from the Java world so if you are new to them I would use them with caution at first.
In the abstract types example you will notice that the abstract type 'I' in Foreach is not within the trait Source rather it is outside in the Foreach trait. At first one might consider putting the type in Source rather than Foreach. The naive change can get you in trouble (but there is a couple easy fixes) Compiling the class results in a compilation error: So what is the problem? 並列処理でWebコンテンツをダウンロードする方法 - Groovy, Scala, C#, Java, Ruby - なんとなくな Developer のメモ. 複数のWebコンテンツ(HTMLや画像など)をダウンロードする際に 1件ずつ処理していたのでは非効率です。 というわけで、並列的にWebコンテンツをダウンロードするプログラムを Groovy, Scala, C#, Java, Ruby で実装してみました。 主な仕様は以下で、外部ライブラリを使用せずに実装しました。 実行時の第1引数で出力先ディレクトリを指定ダウンロード対象の URL を標準入力で指定(改行区切りで複数指定)URL 内のファイル名を出力ファイル名として使用 Groovy の場合 Groovy 1.8 では GPars が同梱されているので、GPars による並列コレクションを使えば簡単に実装できます。
GParsExecutorsPool.withPool に渡したクロージャ内のコレクションで並列処理用のメソッド(下記の eachParallel)が使えるようになります。 Groovy 1.8.2 download_web.groovy Scala の場合 Scala 2.9 では並列コレクションが使えます。 ただし、デフォルトでは JVM が使用できるプロセッサ数※までしか並列化されないようなので、今回のような用途では並列数が少ないかもしれません。 ※ scala.collection.parallel.availableProcessors で数値を参照可 実際には java.lang.Runtime.getRuntime().availableProcessors() の値が設定されている なお、ファイル保存処理を簡単に実装するため、JavaSE 7 で導入された java.nio.file.Files クラス等を使用しています。 Scala 2.9.1(JavaSE 7 依存) download_web_scala C# の場合 .NET Framework 4 では並列タスクが使えます。 .NET Framework 4 DownloadWeb.cs Java の場合 Java の場合、今のところ並列コレクション等の仕組みが用意されていないようなので Concurrency Utilities を使って実装しました。 下記では URL クラスの代わりに URI を使っていますが、特に深い理由は無く Scala のサンプルと同様に URL クラスを使っても問題ありません。
How can I handle 403s with XML.load in Scala.
Still loving the Scala - Richard Dallaway. May 10, 2009 The other night I sat down to satisfy just one more quick-fix screen-scraping twitter-based itch. Of course I decided to scratch using Scala, and it really is an attractive language for "doing stuff". It also made me reflect on how Scala has already started to changed the way I write software. Here's the itch: If you live in the centre of the pebble-beach city of Brighton, and have a dog, the tide times become really interesting, because at low tide sand is revealed, and [sand is fantastic to play fetch in][].
You can get Brighton tide times from VisitBrighton.com, but of course I want the information at the point I'm going to use it. The problem could be boiled down to curl -> grep/sed/awk -> curl, but there's the added complication that tide times are in GMT, and I want to tweet them corrected for daylight saving. So with that background out of the way, here we go... In essence I want to get the tide times for a given date: val tide_times = VisitBrightonScraper.lowsFor(today)
ゆろよろ日記. Sending Play Framework File Uploads to Amazon S3. UPDATE: I’ve released a S3 Play Module based on this project. A couple of questions [1, 2] on StackOverflow.com led me to look into how we can send file uploads in a Play Framework application to Amazon S3 instead of the local disk. For applications running on Heroku this is especially important because the local disk is not persistent. Persistent disk storage makes it hard to scale apps. Instead of using the file system, it’s better to use an external service which is independent of the web tier.
While at JavaZone I sat down with Peter Hilton and Nicolas Leroux to come up with a way to handle this. It only took us 30 minutes to get something working – start to finish – including setup time. This is what is so compelling about Play Framework. All of the code for the sample application is on github: The basics of what we did was this: The app/models/Document.java JPA Entity has three fields – the file being of type S3Blob: That’s it! Getting Started — Typesafe Console Documentation. Sbt-atmos If you use sbt, see the sbt-atmos plugin for an easy way to get started with Typesafe Console for development. Instrumentation To gather information about your application, classes are instrumented with Aspectj. You need to add a java agent to your application, and include the aspects on the classpath. The Aspectj Weaver is included in the developer distribution at: lib/weaver/aspectjweaver.jar And adding this as a java agent requires something like: java -javaagent:lib/weaver/aspectjweaver.jar ...
The tracing aspects can be found in the repo.typesafe.com maven repository, and are available for: Akka 2.0, 2.1, and 2.2Play 2.1 and 2.2 Here are the dependency details for Typesafe Console 1.3.0. Akka 2.0 and Scala 2.9: "com.typesafe.atmos" % "trace-akka-2.0.5" % "1.3.0" Akka 2.1 and Scala 2.10: "com.typesafe.atmos" % "trace-akka-2.1.4" % "1.3.0" Akka 2.2 and Scala 2.10: "com.typesafe.atmos" % "trace-akka-2.2.1_2.10" % "1.3.0" Akka 2.2 and Scala 2.11: Play 2.1 and Scala 2.10: Trace configuration.
Scala(Dispatch)でTumblrのAPIを叩く(ライブラリ化編) | PAB@求職活動中. Connect to RabbitMQ Using Scala, Play and Akka. In this article we'll look at how you can connect from Scala to RabbitMQ so you can support the AMQP protocol from your applications. In this example I'll use the Play Framework 2.0 as container (for more info on this see my other article on this subject) to run the application in, since Play makes developing with Scala a lot easier.
This article will also use Akka actors to send and receive the messages from RabbitMQ. What is AMQP First, a quick introduction into AMQP. AMQP stands for "Advanced Message Queueing Protocol" and is an open standard for messaging. The AMQP homepage states their vision as this: "To become the standard protocol for interoperability between all messaging middleware". There are a number of tools implementing this protocol, but one that is getting more and more attention is RabbitMQ. In this article we'll show you how to do implement the two most common scenarios: I assume you've got an installation of RabbitMQ. Setup basic Play 2 / Scala project 08.play! 11. 08. Tutorial: Play Framework 2 with Scala, Anorm, JSON, CoffeeScript, jQuery & Heroku.
Play Framework 2 RC2 has been released and it is quickly becoming a mature and productive way to build modern web apps. Lets walk through building a quick app with Play 2, Scala, Anorm, JSON, CoffeeScript, and jQuery. Once the app works locally we will deploy it on the cloud with Heroku. (Note: This is the Play 2 + Scala version of my Play 1 + Java tutorial.) You can grab the completed source from GitHub. Step 1) Download and install Play 2 RC2 Step 2) Create a new application: When prompted select to use Scala as the language. Step 3) In the newly created “foobar” directory generate the IDE config files if you’d like to use one. Note: This generates an iml file which is not directly importable as a project. For Eclipse, run: Step 4) Start the Play server: Test that it works by visiting: Step 5) Play 2 with Scala doesn’t provide an ORM by default.
Anorm can use a Scala “case class” as a Value Object and a singleton object as the persistence / CRUD interface. Great! Twitterでも利用されているメッセージキュー Kestrelを試す - ゆるよろ・オブ・ザ・( ;゚皿゚)ノシΣ フィンギィィーーッ!!! 日記. ついったーさんやってますか? ついったーさんのバックエンドは、実はscalaで書かれているってご存じですか? 急成長するついったーさんのバックエンドを支えるなんてすごいですねscala! ついったーさんとscalaのお話は、こちらを参考に。 Twitter on Scala で、Kestrelというメッセージキューが、ついったーさんのバックエンドの一部で利用*1されています。 Robey/kestrel · GitHub このKestrelはオープンソースで誰でも利用することができます。 Kestrelの特徴 READMEに書いてあるものをものっそいてきとうに意訳します。 Kestrel is: fast It runs on the JVM so it can take advantage of the hard work people have put into java performance. small Currently about 1.5K lines of scala (including comments), because it relies on Apache Mina (a rough equivalent of Danger's ziggurat or Ruby's EventMachine) and actors -- and frankly because Scala is extremely expressive. durable Queues are stored in memory for speed, but logged into a journal on disk so that servers can be shutdown or moved without losing any data. reliable A client can ask to "tentatively" fetch an item from a queue, and if that client disconnects from kestrel before confirming ownership of the item, the item is handed to another client.
高速なんだぜ? Kestrelのダウンロード、ビルド. Twitter が Scala 大好きすぎて (?) 設定ファイルまで Scala のソースコードな件 - scalaとか・・・ Using Akka Actor in Play2.0. I 've been learning Play framework 2.0 for a while. The documentation did a relatively decent job, it has some minor typos and doesn't cover all the framework features, which are totally understandable since it is still a working progress. The samples ship with the framework are really really good, you can really learn lots from the samples, and of course there is scala doc. However, if you like me: a scala newbie doesn't have too much experiences with Akka, SBT, and other scala libraries play based on; Learning play seems to be an overwhelming task at the beginning.
This blog attempts to give an introduce how to use Akka Actor in play 2.0. Content: 1. 2. 3. I assume you have some understanding about Actor model, if not, dont worry there are plenty articles give you a nice and short introduce about actor model, like this one . Since Play 2.0 has build-in support for Akka 2.0, so you dont have to create Actor System by yourself. Bootstrap、Hogan.js、Finagleなど注目のTwitter系オープンソース. 「Twitter Open House」はTwitter社のエンジニアと直接情報交換ができるオフラインイベントで、すでにサンフランシスコの本社では何度か開催している。 先日、日本では初めてとなる「Twitter Tokyo Open House」がTwitter Japanのオフィスで開催された。 季節外れの大型低気圧により天候は荒れ、開催すら危ぶまれたが、結果としては多くのエンジニアが集まり盛況なイベントとなった。 OpenJDKにも参加するTwitterのアーキテクチャ 最初に講演を行ったのはTwitterのアーキテクチャのディレクターであるロブ・ベンソン氏。
なでしこジャパンや天空の城ラピュタを例に挙げ、予測不可能で急激な負荷上昇がいつでも発生し得るというTwitterのサービスの性質と、それに耐えうるシステムをいかに構築しているかを語った。 鍵となるのは処理の非同期化とバックエンドシステムの疎結合化だ。 当初TwitterはRuby Enterprise Edition上で動くRuby on Rails(以下、Rails)ベースのモノシリックなアプリケーションだったという。 ■ オープンなJDKに参加するTwitter OpenJDKといえば、Twitter Tokyo Open Houseが開催された後のJava One Tokyo 2012の基調講演にもベンソン氏はゲストとして登壇し、TwitterのOpenJDKへの参加や、今後のJavaへの期待などを語った。 講演の様子は、Togetterで確認してほしい。 ■ ハイパフォーマンスなTwitterを支える「Finagle」 Twitterでは開発言語にJavaやScalaを多用しており、多数のサービス群を独自のRPCフレームワークであるFinagleを使って疎結合にしたTwitterならではのユニークなアーキテクチャになっている。 FinagleはTwitterが独自に開発したRPC(Remote Procedure Call)フレームワークで、ハイパフォーマンスのネットワークサーバ/クライアント基盤である「Netty」の上に構築されている。 Scalaで書かれているためJVM系の多言語(JavaやGroovy、Scala)もサポートしている。 Twitter4Jの中の人が語るTwitterとオープンソース. 50 million messages per second - on a single machine.
50 million messages per second on a single machine is mind blowing! We have measured this for a micro benchmark of Akka 2.0. As promised in Scalability of Fork Join Pool I will here describe one of the tuning settings that can be used to achieve even higher throughput than the amazing numbers presented previously. Using the same benchmark as in Scalability of Fork Join Pool and only changing the configuration we go from 20 to 50 million messages per second. The micro benchmark use pairs of actors sending messages to each other, classical ping-pong. All sharing the same fork join dispatcher. Hardware and configuration: Here is the result of using different values for the throughput setting of the dispatcher. 5 is the default value.
As you see the number of processed messages per second increase dramatically with increased throughput configuration setting up to 20. When using even higher throughput values the curve becomes more flat, but with a maximum above 50 million messages per second. Scala XML Pattern matching and Attributes. [scala] - YoYの日記. 文字コード変換メソッド - MEMO:はてな支店. イトウ アスカ Blog | 斜陽産業と言われてもめげない SE(笑)の記録. Cabal-devとghcmod.vim [追記] Cabal 1.18 で sandobox という機能が入ったため、cabal-dev はその役目を終えたそうです。 トホホ… VimでHaskellプログラミングをする際、ghcmod.vimには大変お世話になっています。 ただ、cabal-devを使っている場合、なんか上手く動かないな、どうしたら上手く動くように設定できるのだろうなとずっと悩んでいました。 その対処法がだいたい見えてきたので紹介します。 Localrcとの合わせ技です。 まず、そもそもghc-modをコマンドラインで使うにはどうすればいいかです。 これはhello.hs内でcabal-devでinstallしたモジュールを使っているとエラーがでます。 このコマンドラインで追加したオプションは、ghcmod.vimにおいてはghcmod_ghc_optionsで指定できます。 次にcabal-devプロジェクトルートに.local.haskell.vimrcというファイルを以下の様な内容で作ります。 以上です。 Scalaの開発環境について いつもは IntelliJ IDEA + Scala プラグインで Scala の開発をしていますが、ファイルによってすごくもっさりするので、他の開発環境はどうだろうかと試してみました。 Read more » Scala 2.10 からの型クラス2(Functorはどうする?)
前回の記事にコメントをいただいて、Functor とか Monad なんかの高階型はどうするのか改めて考えてみました。 結論から言うと Scala は関数リテラルで型パラメータとれないので、関数リテラルだけでなんとかしようというのは不可能っぽいです(いまんところの私の頭では)。 しかし、implicity 使ったり context-bound を使わなくてもなんとかなりそうです。 ということで、Functor をやってみます。 Scala だと Option 型に適用してみます。 使い方。 Def は撲滅できませんでしたが、context-bound が撲滅できるのが私個人としては嬉しいです。 でも、この fmap、カリー化を用いた部分適用(という言い方でいい?) Scala 2.10 からの型クラス でもこの方式、context-bound 型パラメータ使うんですよね。 使い方。 Jetty7のWebSocketをScalaから使う - ゆろよろ日記. Getting code coverage in the Play Framework using Jacoco - ronalleva.com.
なかの日記 - Adding test resources to play framework 2.0 application. [2.0] Unit test resources not copied to target/scala-2.9.1/test-classes - Google グループ. Connect to RabbitMQ (AMQP) using Scala, Play and Akka. Scalatra/example/src/main/scala/org/scalatra/MeteorChatExample.scala at develop · scalatra/scalatra. Scaling out messaging applications with Scala Actors and AMQP. Building Distributed Systems in Scala. User and support list for MongoDB, a NoSQL database. Bjartek/computer-database-mongo. Filter a list by type by using manifests in Scala. Storage of pickled Scala signatures in class files.
Leon/play-salat. PlayFramework 2.0 Javaと WebSocketでつくる リアルタイムMVC Webアプリケーション.