Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Crash course happstack

Name: Anonymous 2011-10-07 2:36

running through happstack crash course.
time to do something, /prog/
no more sitting on your ass and slacking off!
join me and post results.

http://happstack.com/docs/crashcourse/index.html

Name: Anonymous 2011-10-07 2:53

>>1 (Cont)

first thing is probably getting everything installed and ready for coding.

google'd for my installation instructions (ubuntu), seems pretty straightforward.
okay there's no haskell platform for ubuntu
installing ghc and a heap of libraries, ugh, installing cabal... updating $PATH... upgrading cabal-install... shit takes forever. ok done. cabal install happstack works from the first or second try.

create a new directory, create a new ``GNU screen'' window and make watch.sh to run during development:


while true;
do
  # run the program
  runhaskell $1 &
  until nc -z localhost 8000; do :; done; 

  # open a browser
  firefox -remote "openurl(http://localhost:8000)"

  # listen for changes to the source code
  inotifywait -q -q -e modify $1

  # kill the program
  killall ghc
  while nc -z localhost 8000; do :; done; 
done


I create a file called server.hs and start editing it in another window (with vi).
then i start ./watch server.hs
everything seems to work

Name: Anonymous 2011-10-07 3:03

>>2

killall ghc
Could have been nicer I guess, but when i tried something like "kill $!" it didn't work; seems there were two ghc processes running and I needed to kill both of them to ensure the server shutdown completely (and thus freed the port it needed to boot up).

FWIW: The second process seemed to have a PID that was $!+1 but I'm not sure if that's true all the time.

okay so the first program to run is Hello World!, let's try it and see what it gives us:


module Main where

import Control.Monad
import Happstack.Server (nullConf, simpleHTTP, ok, dir)

main :: IO ()
main = simpleHTTP nullConf $ ok "Hello, World!"


Saving the file makes firefox open a new tab with the results.
Seems to work nicely so far.
Let's benchmark this against a simple PHP page.

Name: Anonymous 2011-10-07 3:09

NB: When we check the headers of the happstack application:


~ $ curl -I localhost:8000
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Connection: Keep-Alive
Content-Type: text/plain; charset=UTF-8
Date: Fri, 07 Oct 2011 07:06:02 GMT
Server: Happstack/6.2.4

Name: Anonymous 2011-10-07 3:11

>>4
NB:
only faggots use latin abbrevs

Name: Anonymous 2011-10-07 3:21


<?php print "Hello, World!" ?>



Requests per second:    10.79 [#/sec] (mean)
Time per request:       463.478 [ms] (mean)
Time per request:       92.696 [ms] (mean, across all concurrent requests)
Transfer rate:          52.14 [Kbytes/sec] received


and for happstack:


Requests per second:    7784.40 [#/sec] (mean)
Time per request:       0.642 [ms] (mean)
Time per request:       0.128 [ms] (mean, across all concurrent requests)
Transfer rate:          1170.70 [Kbytes/sec] received


Happstack wins!
twas not all for naught!
but can it actually do more than hello world?

let's try building a semi complex web application

Name: Anonymous 2011-10-07 5:02

>>6
it'll be the same with rails; as long as you only serve semi-static "helloworld2 - electric boogaloo" applications with it, it will be OMG SUPERDUPERFAST

but as soon as you write actual web applications with it, it will run so mindchurningly slow that you might as well just clientside javascript for content generation.

i shit you not, or why do you think rubyists use javascript so much?

Don't change these.
Name: Email:
Entire Thread Thread List