You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 13, 2018. It is now read-only.
I implemented the code from the echo server example (pasted below for your convenience)
Throughput decreases dramatically as the number of requests (=lines, the request type for Echo as Service because of the LineCodec) submitted increases:
Number of requests
Requests/second
10,000
94,900
500,000
1,170
10,000,000
150
The server process is spinning at 100% CPU while doing this.
You have to divide the bytes/s by two to get requests/s since each request (line) is 2 bytes. You can also wait for the command to finish and divide the time reported by the second dd instance by the count= number.
// [dependencies]// bytes = "0.4"// futures = "0.1"// tokio-io = "0.1"// tokio-core = "0.1"// tokio-proto = "0.1"// tokio-service = "0.1"externcrate bytes;externcrate futures;externcrate tokio_io;externcrate tokio_proto;externcrate tokio_service;use std::io;use std::str;use bytes::BytesMut;use futures::{future,Future,BoxFuture};use tokio_io::{AsyncRead,AsyncWrite};use tokio_io::codec::{Encoder,Decoder,Framed};use tokio_proto::pipeline::ServerProto;use tokio_proto::TcpServer;use tokio_service::Service;pubstructLineCodec;implDecoderforLineCodec{typeItem = String;typeError = io::Error;fndecode(&mutself,buf:&mutBytesMut) -> io::Result<Option<String>>{ifletSome(i) = buf.iter().position(|&b| b == b'\n'){// remove the serialized frame from the buffer.let line = buf.split_to(i);// Also remove the '\n'
buf.split_to(1);// Turn this data into a UTF string and return it in a Frame.match str::from_utf8(&line){Ok(s) => Ok(Some(s.to_string())),Err(_) => Err(io::Error::new(io::ErrorKind::Other,"invalid UTF-8")),}}else{Ok(None)}}}implEncoderforLineCodec{typeItem = String;typeError = io::Error;fnencode(&mutself,msg:String,buf:&mutBytesMut) -> io::Result<()>{
buf.extend(msg.as_bytes());
buf.extend(b"\n");Ok(())}}pubstructLineProto;impl<T:AsyncRead + AsyncWrite + 'static>ServerProto<T>forLineProto{/// For this protocol style, `Request` matches the `Item` type of the codec's `Decoder`typeRequest = String;/// For this protocol style, `Response` matches the `Item` type of the codec's `Encoder`typeResponse = String;/// A bit of boilerplate to hook in the codec:typeTransport = Framed<T,LineCodec>;typeBindTransport = Result<Self::Transport, io::Error>;fnbind_transport(&self,io:T) -> Self::BindTransport{Ok(io.framed(LineCodec))}}pubstructEcho;implServiceforEcho{// These types must match the corresponding protocol types:typeRequest = String;typeResponse = String;// For non-streaming protocols, service errors are always io::ErrortypeError = io::Error;// The future for computing the response; box it for simplicity.typeFuture = BoxFuture<Self::Response,Self::Error>;// Produce a future for computing a response from a request.fncall(&self,req:Self::Request) -> Self::Future{// In this case, the response is immediate.
future::ok(req).boxed()}}fnmain(){// Specify the localhost addresslet addr = "0.0.0.0:12345".parse().unwrap();// The builder requires a protocol and an addresslet server = TcpServer::new(LineProto, addr);// We provide a way to *instantiate* the service for each new// connection; here, we just immediately return a new instance.
server.serve(|| Ok(Echo));}
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I implemented the code from the echo server example (pasted below for your convenience)
Throughput decreases dramatically as the number of requests (=lines, the request type for
Echo as Service
because of theLineCodec
) submitted increases:The server process is spinning at 100% CPU while doing this.
Benchmark:
You have to divide the bytes/s by two to get requests/s since each request (line) is 2 bytes. You can also wait for the command to finish and divide the time reported by the second dd instance by the count= number.
This was previously filed as tokio-rs/tokio#14
Code:
The text was updated successfully, but these errors were encountered: