library(tidyverse)

read_csv("garage-v0.7.csv") %>% add_column(daemon="garage 0.7.3") -> a
read_csv("garage-v0.8.csv") %>% add_column(daemon="garage 0.8.0 beta") -> b
read_csv("minio-20220917.csv") %>% add_column(daemon="minio RELEASE.2022-09-17") -> c
bind_rows(a,b,c) %>% group_by(daemon,endpoint) %>% summarise(
  time_mean = mean(nanoseconds) / 1000 / 1000,
  time_max = max(nanoseconds) / 1000 / 1000,
  time_min = min(nanoseconds) / 1000 / 1000
) -> c

st <- "100 measurements, 5 nodes, 50ms RTT + 10ms jitter between nodes\nno contention: latency is due to intra-cluster communications\ncolored bar = mean latency, error bar = min and max latency"


ggplot(c, aes(x=endpoint,y=time_mean,fill=daemon,ymin=time_min,ymax=time_max)) +
      geom_bar(stat="identity", position=position_dodge(),color="black") +
      geom_errorbar(position=position_dodge(.9),width=.2) +
      scale_y_continuous(expand=c(0,0))+
      coord_flip() +
      labs(
        x="S3 Endpoint",
        y="Request duration (ms)",
        fill="Daemon",
        caption="Get the code to reproduce this graph at https://git.deuxfleurs.fr/Deuxfleurs/mknet",
        title="S3 endpoint latency in a simulated geo-distributed cluster",
        subtitle=st) +
      theme_classic() +
      theme(legend.position = c(.8, .3))

ggsave("./plot.png", width=200, height=110, units="mm")
