Skip to content

Instantly share code, notes, and snippets.

View tfutada's full-sized avatar

Takashi Futada tfutada

View GitHub Profile
@tfutada
tfutada / vegeta.rs
Created December 12, 2022 12:22
HTTP load testing tool to study Rust language.
// usage:
// $ cargo build --bin vegeta --release
// $ ./target/release/vegeta -u http://localhost:8000/foo -r 5 -d 30
// generates 5 requests per second, during 30 seconds, targeting to http://localhost:8000/foo
use std::time::{Duration, Instant};
use tokio::sync::mpsc;
use histogram::Histogram;
use std::io::{self, Write};
use anyhow::Result;
use tokio::sync::mpsc::Sender;
@tfutada
tfutada / ratelimit.rs
Last active June 16, 2022 23:52
Ratelimit with Rust hyper and Redis
use anyhow::Result;
use chrono::prelude::*;
use http::HeaderValue;
use std::net::IpAddr;
use std::{convert::Infallible, env, net::SocketAddr};
use hyper::server::conn::AddrStream;
use hyper::service::{make_service_fn, service_fn};
use hyper::{Body, Request, Response, Server, StatusCode};
package main
import (
"strings"
"fmt"
"log"
"net/http"
"io/ioutil"
"github.com/aws/aws-sdk-go/aws/session"