---
# System prepended metadata

title: Nea RFP 1

---

# Nea RFP 1

## Milestone 1

> Implement a custom global allocator that performs one big allocation (using mmap or equivalent)

The core of the memory allocator is here 

https://github.com/tweedegolf/nea/blob/58c4d71528b311e89a59550887a4b9a6b96a02ef/shared/src/allocator.rs

the actual implementation of the `GlobalAlloc` trait is here (so that we can do some custom logging)

https://github.com/tweedegolf/nea/blob/58c4d71528b311e89a59550887a4b9a6b96a02ef/nea/src/lib.rs#L111

This allocator uses some static memory for allocations before main, then performs one `mmap` call to get sufficient memory for the actual program.

> Distribute arenas among threads

This is implicit. The allocator has the concept of a "bucket", a region of memory that we use for serving a request. The async executor (see below) sets a thread-local variable to the current bucket index, and the allocator will then automatically allocate in that bucket for that thread.

> Ensure this allocator works on unix systems (specifically Linux and MacOs)

We've validated the examples on x86 linux and macos. The goal here is mostly to make sure it compiles, i.e. that we don't make platform-specific assumptions.

PS The `oom` example does not currently work on macos, but that is not an allocator problem. (something is wrong with setjmp/longjm).

## Milestone 2

> Implement a custom rust async runtime with TCP sockets and async IO thread using mio 

this logic lives here

https://github.com/tweedegolf/nea/blob/58c4d71528b311e89a59550887a4b9a6b96a02ef/nea/src/executor.rs
https://github.com/tweedegolf/nea/blob/58c4d71528b311e89a59550887a4b9a6b96a02ef/nea/src/reactor.rs

The reactor uses mio to respond to OS events (read/write unblocked). In effect this calls a callback (`Waker`) that enqueues the task so that the executor will process it again. The reactor also provides its own `TcpStream` type that hooks into the async machinery. 

The executor is built around a fixed-size queue

> allow the handler to make httpv1 requests 

Making requests with HTTP1 is supported, see the `hyper` example. This turned out to be difficult because of how hyper uses RAAI.

> Integrate it with the custom allocator 

The custom allocator is configured here

https://github.com/tweedegolf/nea/blob/58c4d71528b311e89a59550887a4b9a6b96a02ef/nea/src/lib.rs#L111

and e.g. here a bucket is cleared so that it can be used for another request

https://github.com/tweedegolf/nea/blob/58c4d71528b311e89a59550887a4b9a6b96a02ef/nea/src/executor.rs#L394
