Git Product home page Git Product logo

libapi's Introduction

libapi

libapi is a cross platform high performance io library written in C. It provides ability to write event driven servers and applications with continous code.

Preface

Writing event driven code in C is hard, and is harder to maintain.

There are libraries providing high level abstractions in this area, one of bests is a popular libuv. But decoupling application logic in various callbacks does not solve problem a lot.

By doing some research I come across combination of tasks also known as coroutines or fibers, and epoll/IOCP.

libapi was developed to solve this problem.

Features

  • cross platform (tested on ubuntu and on windows)
  • high performance (benchmarks will be provided)
  • no locks, no blocking
  • easy to scale
  • easy to develop
  • timeout handling
  • timers and idles
  • bandwidth calculations
  • filters
  • error handling
  • proxy
  • ipv4 and ipv6
  • open source
  • ssl stack with openssl
  • http basic stack
  • keep-alive with timeouts
  • http pipelining
  • https as ssl filter

for complete examples see demos

Architecture

Main concepts are loop, stream and a task.

loop is an abstraction over epoll and IOCP, tht runs on a single thread. By starting a new loop new thread will be created. Each loop has its own pool to alloc/free memory.

stream is an abstraction over file, tcp, utp, pipe, tty and memory. Currently only file and tcp was implemented.

tasks are execution units with seperate stacks that they can be run in parallel within a single loop (single thread). In general scheduler will suspend a task that issued an io operation and will resume one for which an io operation was completed. This allows to keep stack variables alive during events in a loop, and as a result allows writing syncronous code. A task will be created as a result of calls api_loop_start, api_loop_post, api_loop_exec, api_loop_run

Documentation

see libapi/include/api.h

Community

Problems

Stack

Creating a task requires also creating stack for it. Creating large stack is memory consuming, creating small stack will cause stack overflow. But what is bad that we dont know how much stack size will be needed for a particular task. By default will be created 8kb stack for a task. If task needs small stack this is not justified and memory consumed. In case when task needs more stack api_loop_call was designed.

The question is how grow up stack automatically on demand ?

libapi's People

Contributors

xnko avatar

Watchers

 avatar

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.