Giter Club home page Giter Club logo

hinge's Introduction

Hinge. A synonym for node.

An evented framework for Common Lisp. Driven by libev, like the cool kids.

Check out the wiki for docs and writeups and stop by the #hinge channel on Freenode to bug me in real time.

Requirements

System level dependencies

CCL is also supported, but SBCL is the primary development platform, and is favored in the makefiles.

Dependencies built outside of quicklisp

These deps are fetched and built with make develop

Quickstart

Clone and init the project

# Clone the repo
$ git clone https://github.com/sshirokov/hinge.git
$ cd hinge

# Init the enviornment
$ make develop

Once you run make develop you're free to use Hinge in other Lisp systems as long as you don't relocate the project directory.

Fire up the REPL and evaluate the following. It should boot up and keep running an HTTP server on port 4545

(ql:quickload :hinge)
(defpackage :hinge-example
  (:use :cl :hinge :hinge.http))

(in-package :hinge-example)

(let ((server (make-instance 'http-server)))
  (add-listener server "request"
                (lambda (request response)
                  (declare (ignorable request))
                  (write-head response 200 '(("Content-Type" . "text/html")))
                  (end response "Hello world!")))

  (bind server 4545))

(run :default)

You should now be able to throw HTTP requests at localhost:4545 with something like curl and get replies:

$ time curl -i localhost:4545
HTTP/1.1 200 OK
Content-Length: 12
Content-Type: text/html

Hello world!
real	0m0.006s
user	0m0.004s
sys	0m0.000s

You can also throw something like ab at it, which is somewhat mandatory despite being a poor benchmark:

$ ab -c 10 -n 1000 http://localhost:4545/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:
Server Hostname:        localhost
Server Port:            4545

Document Path:          /
Document Length:        12 bytes

Concurrency Level:      10
Time taken for tests:   0.397 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      51000 bytes
HTML transferred:       12000 bytes
Requests per second:    2519.51 [#/sec] (mean)
Time per request:       3.969 [ms] (mean)
Time per request:       0.397 [ms] (mean, across all concurrent requests)
Transfer rate:          125.48 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     2    3   9.7      3     214
Waiting:        1    2   9.6      2     213
Total:          2    3   9.7      3     214

Percentage of the requests served within a certain time (ms)
  50%      3
  66%      3
  75%      3
  80%      3
  90%      3
  95%      3
  98%      4
  99%      5
 100%    214 (longest request)

hinge's People

Contributors

sshirokov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hinge's Issues

Testing support

There should be some sort of wrapper, ideally for NST to support unit testing within the Hinge reactor.

It could scaffold the NST environment then begin the evaluation of tests in response to events. Nothing too fancy.

Socket option wrappers

The socket, server and zmq-socket classes lack nicer wrappers for setting socket options, backlog settings and zmq_socket options without reaching into the wrapping class to the underlying handle.

These methods should exist as first class wrappers.

conserv

Hey,

I've been developing something very similar to this. You can check it out at http://github.com/sykopomp/conserv. I'd been thinking of trying to use libev instead of iolib to see if there was any difference in performance and portability. How has cl-ev been working out for you?

Basic Async FS access

Need basic async APIs for

  • File open
  • File read
  • File write
  • File rename

This ticket should also implement the stat watcher from libev and include an API for it's operation.

Libev recommends against using IO watchers for disk-based descriptors, so this work might be best carried out in the threadpool.

Can't initialize submodules

When I try to do this:

git submodule update --init --recursive

I get this:

Submodule 'vendor/cffi' () registered for path 'vendor/cffi'
Submodule 'vendor/cl-ev' () registered for path 'vendor/cl-ev'
Submodule 'vendor/lisp-zmq' () registered for path 'vendor/lisp-zmq'
fatal: Needed a single revision
Unable to find current revision in submodule path 'vendor/cffi'

What should I do?

make develop fails

When I run `make develop' (CentOS 6.4 x86_64) with the latest hinge cloned off of github, at some point make produces the following:

make[1]: Entering directory `/home/icon/tools/hinge/vendor'
=> Updating submodules
(cd .. ; git submodule update --init --recursive;)
Initialized empty Git repository in /home/icon/tools/hinge/vendor/cl-ev/.git/
Warning: Permanently added the RSA host key for IP address '192.30.252.131' to the list of known hosts.
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
Clone of '[email protected]:sshirokov/cl-ev.git' into submodule path 'vendor/cl-ev' failed
make[1]: *** [init] Error 1
make[1]: Leaving directory `/home/icon/tools/hinge/vendor'
make: *** [init] Error 2

I'm not sure if this is an issue with hinge or something else, but I can ping the stated address and I can clone cl-ev manually into vendors/cl-ev, after which rerunning `make develop' finishes successfully with 'You should be good to go'.

Initial Docs

The links in https://github.com/sshirokov/hinge/wiki/Classes should be filled in to describe
the classes in the headers and the methods that are specialized for them

A quick tutorial should also be written that walks from installing a LISP implementation
to getting a functional HTTP "Hello World" application in a different package.

Defer should not use a timer

The defer macro should schedule the execution of the thunk into the emit or deliver queues rather than scheduling a brand new one-off timer.

This might mandate that the queue API grows up a little.

ZeroMQ sockets should not drain in a blocking manner on-read

Right now the on-read callback for a zmq-socket drains the 0MQ socket in a blocking function in the I/O callback until the read would block before returning from the callback.

Instead, the on-read callback should start a high-priority idle watcher (Higher than the delivery watcher, and if this approach is taken the priority values should be externalized to something resembling constants) which will then drain the socket until it would block, before resuming the IO callback.

Generalized work queue API

First, wrap emit and deliver into something that uses the running-queue API

Then remove all of the -queue and -runner slots from hinge and unify them into something like an array
indexed by priority or a hash-table keyed by :name.

have you seen luvit

luvit has a very similar concept, and just wrapped libuv v8 and a few others with a similar api as node making it easy to work with with the added fast ffi benefit.
Also Tim Casswell @creationix was really nice education and helpful.
The build steps are "get lit && make luv && luvit` or something comical like that back in the day

Write bundling

Right now the socket on-write callback writes a single buffer to the wire even when multiple writes are queued regardless of the size, this causes less than optimal write performance when many small writes are queued as it forces them to be written in several iterations of the event loop.

Ideally the on-write callback will bundle as many writes as it can into a fixed larger size buffer before attempting to write to get as much data across the wire as possible then fire any callbacks that should be fired as a result of the IO and update the offset in the last logical chunk that it tried and fail to write.

This change would force things like chunked HTTP replies to be written to the wire in larger chunks rather than several tiny writes without affecting the chain of callbacks that has an expectation of being invoked on write completion.

HTTP Client

Hinge needs an Async HTTP client. It should be modeled somewhat on the node.js http.request.

Any state machines that can be reused from the HTTP parser should be reused, like the header reader.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.