Coder Social home page Coder Social logo

grpc_streaming_test's Introduction

This repository contains a grpc-rs server and two clients.

To build:

cargo build

Server

The server implements two streaming rpcs (stream_case_1 and stream_case_2). They are two different ways to implement an infinite stream of results.

The intention is that the server continues pushing items into the stream as long as the client is listening. When the client hangs up the server should stop generating items and sending them to the stream.

Start the server:

./target/debug/server

The server will log each item generated.

Clients

The two clients (client_case_1 and client_case_2) are the same, the only difference being that client_case_1 calls the stream_case_1 rpc while client_case_2 calls the stream_case_2 rpc.

Each client reads the first 100 items from the stream and then sleeps for 10 seconds before quitting. The intention is that the server stops generating and sending items soon after the client has received it's 100 items.

The reason for the 10 second sleep is because the server always stops right away (the good behavior that I want) when the client process exists. On the other hand if the client process doesn't exit sometimes the server keeps generating items even though the client has finished with the steam.

To run a client 1:

./target/debug/client_case_1

To run a client 2:

./target/debug/client_case_2

Each client logs each item received.

Case 1 Problems

Case 1 is the biggest problem case. Notice that after client 1 receives the first 100 items and sleeps the server often keep generating items all the way until until the client process exits. So for example on my computer the server ends up working to generate over 200,000 items each time.

Note that this isn't always the case. Sometimes (especially just after restarting the server) the server will stop generating items pretty quickly after the client has it's first 100. This is what I would want, but isn't the normal behavior.

Case 2 Problems

Case 2 behaves better. The server always stops generating items soon after the client has received the first 100.

But to get this good behavior required a rather messy implementation on the server. I need to setup a channel and then use a separate thread to call try_send on it to send the items. Probably this can be improved?

A second problem is that the server still generates more items then I would expect. Around 1000 for each call. This is surprising to me because the the channel that I'm writing into only has a buffer of 10 items. I don't quite understand why the server is still generating so many.

NOTE I just figured out that case 2 good behavior was also dependent on a println in the code (see comment in code). If I comment that println out then I get bad behavior again. Yipes, I must be doing something pretty wrong!

grpc_streaming_test's People

Contributors

jessegrosjean avatar

Stargazers

tiff avatar

Watchers

 avatar James Cloos avatar

Forkers

tiangong3624749

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.