Simple ‘Hello World’ with equal-sized payloads
$ wrk -c 100 -d 60 http://localhost:3000/hello
Requests/sec: 13,010
Requests/sec: 43,741 ~3.3x
// $ node server.js
const http = require('http');
const server = http.createServer((req, res) => {
if (req.url === '/hello') {
res.end('Hello, world!');
} else {
res.statusCode = 404;
res.end('Not Found');
}
});
server.listen(3000);
// $ osgood app.js
app.port = 3000;
app.get('/hello', 'worker.js');
// worker.js
export default () => "Hello, World!";
Request
comes in, Response
goes out// worker.js
export default function(req) {
const requestBody = await req.json();
const obj = {
echo: requestBody
};
const headers = new Headers({
'Content-Type': 'application/json'
});
const body = JSON.stringify(obj);
return new Response(body, { headers, status });
}
// app.js
app.interface = '127.0.0.1';
app.port = 8080;
app.get('/merge/:user', 'merge.js');
osgood
binary$ osgood app.js
// app.js
app.get('/users', 'list-users.js');
app.get('/users/:id', 'view-user.js');
app.delete('/users/:id', 'delete-user.js');
app.post('/users', 'create-user.js');
app.put('/users/:id', 'update-user.js');
export default async function (request, context) {
const u = context.params.user;
const [gists_req, repos_req] = await Promise.all([
fetch(`https://api.github.com/users/${u}/gists`),
fetch(`https://api.github.com/users/${u}/repos`),
]);
const [gists, repos] = await Promise.all([
gists_req.json(),
repos_req.json(),
]);
return { gists, repos };
}
// app.js
const GISTS = 'https://api.github.com/users/*/gists';
const REPOS = 'https://api.github.com/users/*/repos';
app.get('/merge/:user', 'merge.js', policy => {
policy.outboundHttp.allowGet(GISTS);
policy.outboundHttp.allowGet(REPOS);
});
fetch()
, Request
, Response
, Headers
URL
, URLSearchParams
ReadableStream
, WritableStream
BigInt
class
, private fieldsasync
, await
, import
, export
RegExp
named capture groupslocalStorage
interface?import
require()
async
/await
??????It's like libuv
Except you get threads.
// C++
static void
MyFunction(const FunctionCallbackInfo<Value>& args)
{
Isolate * isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
// ... code goes here ...
args.GetReturnValue().Set(foo);
}
// Rust
#[v8_fn]
fn my_function(args: FunctionCallbackInfo) {
// ... code goes here ...
args.set_return_value(foo);
}
// C++
Local<String> name = String::NewFromUtf8(
isolate,
"value",
v8::NewStringType::kNormal
).ToLocalChecked();
Local<Number> num = Number::New(isolate, 42);
obj->Set(context, name, num);
// Rust
obj.set("value", 42);
( T:CT ⇒ tokio::runtime::current_thread
)
policy.sql.allowRead('users')
IndexedDB
?
policy.sql.allow('SELECT * FROM users')
import template from "./template.hbs";
CacheStorage
API)// app.js
app.get('/', 'worker.js', policy => {
policy.chroot('~/.osgood/', 'config', 'readonly');
});
// worker.js
import file from 'osgood:filesystem';
const conf = await file.read('config', '/conf.json');
export
require('child_process');
@tlhunter
@bengl
IntrinsicLabs/osgood