Swift HTTP server using the pre-fork worker model

Related tags

Webserver Curassow
Overview

Curassow

Build Status

Curassow is a Swift Nest HTTP Server. It uses the pre-fork worker model and it's similar to Python's Gunicorn and Ruby's Unicorn.

It exposes a Nest-compatible interface for your application, allowing you to use Curassow with any Nest compatible web frameworks of your choice.

Documentation

Full documentation can be found on the Curassow website: https://curassow.fuller.li

Usage

To use Curassow, you will need to install it via the Swift Package Manager, you can add it to the list of dependencies in your Package.swift:

import PackageDescription

let package = Package(
  name: "HelloWorld",
  dependencies: [
    .Package(url: "https://github.com/kylef/Curassow.git", majorVersion: 0, minor: 6),
  ]
)

Afterwards you can place your web application implementation in Sources and add the runner inside main.swift which exposes a command line tool to run your web application:

import Curassow
import Inquiline


serve { request in
  return Response(.ok, contentType: "text/plain", body: "Hello World")
}

Then build and run your application:

$ swift build --configuration release

Example Application

You can find a hello world example application that uses Curassow.

License

Curassow is licensed under the BSD license. See LICENSE for more info.

Comments
  • Curassow issues on Cloud Foundry

    Curassow issues on Cloud Foundry

    I had to downgrade to tag 0.2 for the app. to work on Cloud Foundry.

    The Hello World app (pinned to swift 2.2 but don't think that matters) is at

    https://github.com/ragsns/Curassow-example-helloworld

    and the Curassow tag 0.2 (for convenience) is at

    https://github.com/ragsns/Curassow/

    Am I missing something or is it a bug in master branch?

    opened by ragsns 12
  • Performance benchmark

    Performance benchmark

    Here is a simple benchmark result with wrk on my iMac 5K. Just Hello World. Compiled with swift build --configuration release. 4 workers.

    ~ wrk -c 1k -t 10 --timeout 5s --latency http://0.0.0.0:8000/
    Running 10s test @ http://0.0.0.0:8000/
      10 threads and 1000 connections
      Thread Stats   Avg      Stdev     Max   +/- Stdev
        Latency     1.24ms    1.02ms  10.22ms   88.24%
        Req/Sec   557.81      1.17k    6.55k    94.44%
      Latency Distribution
         50%    1.16ms
         75%    1.50ms
         90%    1.96ms
         99%    5.96ms
      3818 requests in 10.10s, 371.77KB read
      Socket errors: connect 757, read 375, write 0, timeout 0
      Non-2xx or 3xx responses: 620
    Requests/sec:    377.98
    Transfer/sec:     36.80KB
    

    About half of the responses are [worker] Failed to decode data from client.

    question 
    opened by lexrus 10
  • Workers timeout when accessing request body

    Workers timeout when accessing request body

    When a request is received, something seems to be sticking when accessing the body's data. It's been reproducible on 0.5.0 100% for me.

    Swift Version: DEVELOPMENT-SNAPSHOT-2016-03-01-a

    Platform: osx

    Minimum Reproducible Example

    serve { req in
        var mutable = req
        print("Body: \(mutable.body?.next())") // will never get past this line
        return Inquiline.Response(.Ok, contentType: "text/html", content: "Did Stuff")
    }
    

    Let me know if I'm doing something wrong here, everything else works, it only fails when I try to use next()

    opened by loganwright 9
  • Recommended debugging techniques

    Recommended debugging techniques

    I was wondering how you approach debugging Curassow (with lldb), since it forks off worker processes at the beginning and lldb doesn't support automatic following of forks.

    I found a very tedious way:

    • run your server in terminal window 1
    • in another window launch lldb for your binary
    • run attach WORKER_PID, which is visible when the server starts
    • continue as usual in the lldb instance, allowing to inspect the incoming requests in the debugger

    This will obviously get untenable as a codebase grows, so I'm wondering what your thoughts on this are.

    opened by czechboy0 6
  • Parse HTTP message body

    Parse HTTP message body

    I was trying to put together a slightly less trivial demo app and realized that there was no logic yet for reading in body data. This is a first pass at implementing that behavior. It only tries to read the body if the Content-Length header is present and doesn't try to deal with Transfer-Encoding at all, but this seems to be sufficient for the basic case that I'm looking for right now.

    opened by briancroom 5
  • Handling binary data

    Handling binary data

    If the body must be represented as a string (Nest spec), how would one respond with binary data? e.g. image/gif? I find myself wanting a more general representation like [UInt8], or even more general, something that can express itself as a sequence (streamable).

    For instance, Ruby's Rack just wants a body that responds to .each.

    opened by danneu 4
  • Update README.md

    Update README.md

    Not 100% sure how the Swift PM works just yet, but if you specify minor: 1, it won't download the latest release (e.g., 0.2.3). I'm assuming minor: 1 limits us to just 0.1.x.

    Came across this issue while trying to install Currasow for the first time via the Swift PM. Everything linked properly when I changed the minor version to 2.

    opened by ArtSabintsev 4
  • Package Manager with

    Package Manager with "12-18-b" Snapshot release of Swift fails to build Curassow

    Hello,

    I've had success building a small example app with the 12-01 Swift snapshot release, but the new 12-18 snapshot release appears to break building Curassow. I'm targeting the 0.2 release of Curassow in my package file, and it's the only dependency I directly declare. Below is the results of running swift build.

    I tracked this down to the SPM throwing an error in https://github.com/apple/swift-package-manager/blob/master/Sources/dep/Manifest+configureTargets.swift#L51 but I can't immediately see why this happens.

    $ swift build
    Cloning Packages/Curassow
    Using version 0.2.0 of package Curassow
    Cloning Packages/Nest
    Using version 0.2.1 of package Nest
    Cloning Packages/Inquiline
    Using version 0.2.2 of package Inquiline
    Cloning Packages/Commander
    Using version 0.4.0 of package Commander
    Compiling Swift Module 'Nest' (1 sources)
    Linking Library:  .build/debug/Nest.a
    Compiling Swift Module 'Inquiline' (3 sources)
    Linking Library:  .build/debug/Inquiline.a
    Compiling Swift Module 'Commander' (8 sources)
    Linking Library:  .build/debug/Commander.a
    swift-build: Your source structure is not supported due to conflicting directories: /path/to/project/Packages/Curassow-0.2.0
    

    Other data:

    OS: Ubuntu 14.04 (so I'm using the -b snapshot build)

    $ uname -a
    Linux ubuntu 3.19.0-25-generic #26~14.04.1-Ubuntu SMP Fri Jul 24 21:16:20 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
    
    $ swift --version
    Swift version 2.2-dev (LLVM 3ebdbb2c7e, Clang f66c5bb67b, Swift 0ddf238ad7)
    Target: x86_64-unknown-linux-gnu
    
    opened by stupergenius 4
  • Increased visibility of Arbiter.stop()

    Increased visibility of Arbiter.stop()

    We need public access to Arbiter.stop() in order to properly integrate as a server driver for Vapor as per https://github.com/qutheory/vapor-curassow-server/pull/1.

    opened by shnhrrsn 3
  • Simplify your Makefile

    Simplify your Makefile

    SPEC_FILES=$(foreach spec,$(SPECS),Tests/$(spec)Spec.swift)
    // add these
    LIB_FILES=$(shell ls .build/debug/*.a)
    STATIC_LIBS=$(foreach lib,$(LIB_FILES),-Xlinker $(lib))
    
    // modify your run-tests
        @$(SWIFTC) -o run-tests \
            Tests/main.swift \
            $(SPEC_FILES) \
            -I.build/debug \
            $(STATIC_LIBS)
    
    opened by ssoper 3
  • Prevent crashing due to SIGPIPE

    Prevent crashing due to SIGPIPE

    By default, calling send on a socket which has been closed on the remote end causes SIGPIPE to be sent to the process, which terminates it. These changes change the behavior to disable the signal, and instead make send return an error code if the socket has been closed.

    This situation arises frequently when deploying to Cloud Foundry, as its healthcheck process opens a connection to the app and then closes without sending any data.

    opened by briancroom 3
Releases(0.6.1)
  • 0.6.1(Apr 7, 2017)

  • 0.5.0(Mar 5, 2016)

  • 0.4.1(Mar 5, 2016)

    Enhancements

    • The WEB_CONCURRENCY environment variable can be used to configure the amount of workers.
    • The PORT environment variable can be used to configure the default listening port.
    • You can now daemonize Curassow via the --daemon option.
    Source code(tar.gz)
    Source code(zip)
  • 0.4.0(Feb 12, 2016)

  • 0.3.0(Jan 24, 2016)

  • 0.2.3(Jan 2, 2016)

  • 0.2.2(Dec 24, 2015)

  • 0.2.1(Dec 24, 2015)

  • 0.2.0(Dec 16, 2015)

    Enhancements
    • Bodies of HTTP requests are now parsed and available to Nest callbacks.
    Bug Fixes
    • Fixes a crash in a worker if a client disconnects before we send a response to them.
    Source code(tar.gz)
    Source code(zip)
  • 0.1.3(Dec 11, 2015)

    Enhancements
    • Curassow now parses request headers and exposes them in the request.
    Bug Fixes
    • Fixes a problem where some requests would fail to be decoded.
    Source code(tar.gz)
    Source code(zip)
  • 0.1.2(Dec 6, 2015)

    Enhancements
    • Improved logger format which shows PID and time of event.
    Bug Fixes
    • Restores Linux compatibility, it was accidentally broken in the previous release by introducing OS X support.
    • Fixes a potential crash when Curassow failed to bind to a port.
    Source code(tar.gz)
    Source code(zip)
  • 0.1.1(Dec 6, 2015)

    Enhancements
    • Adds support for OS X.

    • Allow dynamically changing the worker count using the TTIN and TTOU signals.
      To increase the worker count by one, where $PID is the PID of the master process.

      $ kill -TTIN $PID
      

      To decrease the worker count by one:

      $ kill -TTOU $PID
      
    Bug Fixes
    • Resolves a problem where some HTTP requests we're not getting passed.
    Source code(tar.gz)
    Source code(zip)
  • 0.1.0(Dec 6, 2015)

Owner
Kyle Fuller Archive
Older / Less maintained projects
Kyle Fuller Archive
A Swift web framework and HTTP server.

A Swift Web Framework and HTTP Server Summary Kitura is a web framework and web server that is created for web services written in Swift. For more inf

Kitura 7.6k Dec 27, 2022
Tiny http server engine written in Swift programming language.

What is Swifter? Tiny http server engine written in Swift programming language. Branches * stable - lands on CocoaPods and others. Supports the latest

null 3.6k Jan 3, 2023
Server-side Swift. The Perfect core toolset and framework for Swift Developers. (For mobile back-end development, website and API development, and more…)

Perfect: Server-Side Swift 简体中文 Perfect: Server-Side Swift Perfect is a complete and powerful toolbox, framework, and application server for Linux, iO

PerfectlySoft Inc. 13.9k Dec 29, 2022
💧 A server-side Swift web framework.

Vapor is a web framework for Swift. It provides a beautifully expressive and easy to use foundation for your next website, API, or cloud project. Take

Vapor 22.4k Jan 7, 2023
Lightweight library for web server applications in Swift on macOS and Linux powered by coroutines.

Why Zewo? • Support • Community • Contributing Zewo Zewo is a lightweight library for web applications in Swift. What sets Zewo apart? Zewo is not a w

Zewo 1.9k Dec 22, 2022
Meet Corvus, the first strongly declarative server-side framework.

Corvus Corvus is the first truly declarative server-side framework for Swift. It provides a declarative, composable syntax which makes it easy to get

null 42 Jun 29, 2022
Super lightweight web framework in Swift based on SWSGI

Ambassador Super lightweight web framework in Swift based on SWSGI Features Super lightweight Easy to use, designed for UI automatic testing API mocki

Envoy 170 Nov 15, 2022
A Swift Multiplatform Single-threaded Non-blocking Web and Networking Framework

Serverside non-blocking IO in Swift Ask questions in our Slack channel! Lightning (formerly Edge) Node Lightning is an HTTP Server and TCP Client/Serv

SkyLab 316 Oct 6, 2022
Evented I/O streams for Swift

Noze.io "Das Haus das Verrückte macht." Noze.io is an attempt to carry over the Node.js ideas into pure Swift. It uses libdispatch for event-driven, n

The Noze Consortium 305 Oct 14, 2022
Swift HTTP server using the pre-fork worker model

Curassow Curassow is a Swift Nest HTTP Server. It uses the pre-fork worker model and it's similar to Python's Gunicorn and Ruby's Unicorn. It exposes

Kyle Fuller Archive 397 Oct 30, 2022
Swift HTTP server using the pre-fork worker model

Curassow Curassow is a Swift Nest HTTP Server. It uses the pre-fork worker model and it's similar to Python's Gunicorn and Ruby's Unicorn. It exposes

Kyle Fuller Archive 397 Oct 30, 2022
A fast, convenient and nonintrusive conversion framework between JSON and model. Your model class doesn't need to extend any base class. You don't need to modify any model file.

MJExtension A fast, convenient and nonintrusive conversion framework between JSON and model. 转换速度快、使用简单方便的字典转模型框架 ?? ✍??Release Notes: more details Co

M了个J 8.5k Jan 3, 2023
An example of CoreML using a pre-trained VGG16 model

CoreMLExample In this example we use AVFoundation to continuously get image data from the back camera, and try to detect the dominant objects present

Aleph Retamal 34 Apr 22, 2022
Swift wrapper for Discord's API. Maintained fork of Azoy's Sword.

Sword - A Discord Library for Swift Requirements macOS, Linux, iOS, watchOS, tvOS (no voice for iOS, watchOS, or tvOS) At least Swift 5.3 Adding Sword

Sketch 38 Jan 3, 2023
Swiftcord - Swift wrapper for Discord's API. Maintained fork of Azoy's Sword

Swiftcord - A Discord Library for Swift Requirements macOS, Linux, iOS, watchOS,

Sketch 37 Nov 30, 2022
Code Challenge - Using Alamofire is a Swift-based, HTTP networking library, also Codable for Data Model and Combine Framework .

Code Challenge ##Using Alamofire is a Swift-based, HTTP networking library, also Codable for Data Model and Combine Framework . Alamofire is one of th

Eng Angelo Saber 0 Nov 24, 2021
MacBox - A fork of MacVM that fixes a bunch of UI issues

MacVM Fixes full screen problem by removing toolbar adding start stop to the men

heapwolf 9 Sep 8, 2022
FlyingFox - a lightweight HTTP server built using Swift Concurrency

Usage Credits Introduction FlyingFox is a lightweight HTTP server built using Swift Concurrency. The server uses non blocking BSD sockets, handling ea

Simon Whitty 262 Dec 24, 2022
CoreMLSample - CoreML Example for in app model and download model

CoreMLSample Sample for CoreML This project is CoreML Example for in app model a

Kim Seonghun 2 Aug 31, 2022
Style Art library process images using COREML with a set of pre trained machine learning models and convert them to Art style.

StyleArt Style Art is a library that process images using COREML with a set of pre trained machine learning models and convert them to Art style. Prev

iLeaf Solutions Pvt. Ltd. 222 Dec 17, 2022