Skip to content

Commit

Permalink
adding go docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rok committed Aug 16, 2022
1 parent 2a9a45a commit 4640e31
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 27 deletions.
32 changes: 17 additions & 15 deletions docs/source/cpp/flight.rst
Original file line number Diff line number Diff line change
Expand Up @@ -172,27 +172,28 @@ request/response. On the server, they can inspect incoming headers and
fail the request; hence, they can be used to implement custom
authentication methods.

.. _flight-best-practices:

Best practices
==============

gRPC
----

When using default gRPC transport options can be passed to it via
:func:`arrow::flight::FlightClientOptions.generic_options`. For example:
:member:`arrow::flight::FlightClientOptions::generic_options`. For example:

.. code-block:: cpp
auto options = FlightClientOptions::Defaults();
// Set a very low limit at the gRPC layer to fail all calls
options.generic_options.emplace_back(GRPC_ARG_MAX_RECEIVE_MESSAGE_LENGTH, 4);
See available `gRPC keys_`.
Best gRPC practices are described here_.
Also see `best gRPC practices`_ and available `gRPC keys`_.


Re-use clients whenever possible

--------------------------------

Closing clients causes gRPC to close and clean up connections which can take
several seconds per connection. This will stall server and client threads if
Expand Down Expand Up @@ -257,17 +258,18 @@ different node. Not everyone gets serviced but quality of service stays consiste
Closing unresponsive connections
--------------------------------

* A stale connection can be closed using FlightCallOptions.stop_token. This requires
recording the stop token at connection establishment time.
* Use client timeout
* here is a long standing ticket for a per-write/per-read timeout instead of a per
call timeout (ARROW-6062_), but this is not (easily) possible to implement with the
blocking gRPC API. For now one can also do something like set up a background thread
that calls cancel() on a timer and have the main thread reset the timer every time a
write operation completes successfully (that means one needs to use to_batches() +
write_batch and not write_table).

.. _here: https://grpc.io/docs/guides/performance/#general
1. A stale connection can be closed using
:member:`arrow::flight::FlightClientOptions::stop_token`. This requires recording the
stop token at connection establishment time.
2. Use client timeout.
3. There is a long standing ticket for a per-write/per-read timeout instead of a per
call timeout (ARROW-6062_), but this is not (easily) possible to implement with the
blocking gRPC API. For now one can also do something like set up a background thread
that calls cancel() on a timer and have the main thread reset the timer every time a
write operation completes successfully (that means one needs to use to_batches() +
write_batch and not write_table).

.. _best gRPC practices: https://grpc.io/docs/guides/performance/#general
.. _gRPC keys: https://grpc.github.io/grpc/cpp/group__grpc__arg__keys.html
.. _ARROW-15764: https://issues.apache.org/jira/browse/ARROW-15764
.. _ARROW-16697: https://issues.apache.org/jira/browse/ARROW-16697
Expand Down
5 changes: 2 additions & 3 deletions docs/source/java/flight.rst
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,9 @@ request/response. On the server, they can inspect incoming headers and
fail the request; hence, they can be used to implement custom
authentication methods.

Best practices
==============
:ref:`Flight best practices <flight-best-practices>`
====================================================

TODO

.. _`FlightClient`: https://arrow.apache.org/docs/java/reference/org/apache/arrow/flight/FlightClient.html
.. _`FlightProducer`: https://arrow.apache.org/docs/java/reference/org/apache/arrow/flight/FlightProducer.html
Expand Down
6 changes: 2 additions & 4 deletions docs/source/python/flight.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,5 @@ request/response. On the server, they can inspect incoming headers and
fail the request; hence, they can be used to implement custom
authentication methods.

Best practices
==============

TODO
:ref:`Flight best practices <flight-best-practices>`
====================================================
98 changes: 98 additions & 0 deletions go/arrow/flight/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Here we list best practices and common pitfalls for Arrow Flight usage.
//
// GRPC
//
// When using gRPC for transport all client methods take an optional list
// of gRPC CallOptions: https://pkg.go.dev/google.golang.org/grpc#CallOption.
// Additional headers can be used or read via
// https://pkg.go.dev/google.golang.org/[email protected]/metadata with the context.
// Also see available gRPC keys
// (https://grpc.github.io/grpc/cpp/group__grpc__arg__keys.html) and a list of
// best gRPC practices (https://grpc.io/docs/guides/performance/#general).
//
// Re-use clients whenever possible
//
// Closing clients causes gRPC to close and clean up connections which can take
// several seconds per connection. This will stall server and client threads if
// done too frequently. Client reuse will avoid this issue.
//
// Don’t round-robin load balance
//
// Round robin balancing can cause every client to have an open connection to
// every server causing an unexpected number of open connections and a depletion
// of resources.
//
// Debugging
//
// Use netstat to see the number of open connections.
// For debug use env GODEBUG=http2debug=1 or GODEBUG=http2debug=2 for verbose
// http2 logs (using 2 is more verbose with frame dumps). This will print the
// initial headers (on both sides) so you can see if grpc established the
// connection or not. It will also print when a message is sent, so you can tell
// if the connection is open or not.
// Note: "connect" isn't really a connect and we’ve observed that gRPC does not
// give you the actual error until you first try to make a call. This can cause
// error being reported at unexpected times.
//
// Use ListFlights sparingly
//
// ListFlights endpoint is largely just implemented as a normal GRPC stream
// endpoint and can hit transfer bottlenecks if used too much. To estimate data
// transfer bottleneck:
// 5k schemas will serialize to about 1-5 MB/call. Assuming a gRPC localhost
// bottleneck of 3GB/s you can at best serve 600-3000 clients/s.
//
// https://issues.apache.org/jira/browse/ARROW-15764 proposes a caching
// optimisation for server side, but it was not yet implemented.
//
//
// Memory cache client-side
//
// Flight uses gRPC allocator wherever possible.
//
// gRPC will spawn an unbounded number of threads for concurrent clients. Those
// threads are not necessarily cleaned up (cached thread pool in java parlance).
// glibc malloc clears some per thread state and the default tuning never clears
// caches in some workloads. But you can explicitly tell malloc to dump caches.
// See https://issues.apache.org/jira/browse/ARROW-16697 as an example.
//
// A quick way of testing: attach to the process with a debugger and call malloc_trim
//
//
// Excessive traffic
//
// There are basically two ways to handle excessive traffic:
// * unbounded thread pool -> everyone gets serviced, but it might take forever.
// This is what you are seeing now.
// bounded thread pool -> Reject connections / requests when under load, and have
// clients retry with backoff. This also gives an opportunity to retry with a
// different node. Not everyone gets serviced but quality of service stays consistent.
//
// Closing unresponsive connections
//
// * A stale connection can be closed using CallOptions.stop_token. This requires
// recording the stop token at connection establishment time.
// * Use client timeout
// * here is a long standing ticket for a per-write/per-read timeout instead of a per
// call timeout (https://issues.apache.org/jira/browse/ARROW-6062), but this is not
// (easily) possible to implement with the blocking gRPC API. For now one can also do
// something like set up a background thread that calls cancel() on a timer and have
// the main thread reset the timer every time a write operation completes successfully
// (that means one needs to use to_batches() + write_batch and not write_table).
package flight
1 change: 1 addition & 0 deletions go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PK
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
Expand Down
2 changes: 1 addition & 1 deletion go/parquet/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// Package parquet provides an implementation of Apache Parquet for Go.
//
// Apache Parquet is an open-source columnar data storage format using the record
// shredding and assembly algorithm to accomodate complex data structures which
// shredding and assembly algorithm to accommodate complex data structures which
// can then be used to efficiently store the data.
//
// This implementation is a native go implementation for reading and writing the
Expand Down
5 changes: 1 addition & 4 deletions r/vignettes/flight.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,4 @@ Because `flight_get()` returns an Arrow data structure, you can directly pipe
its result into a [dplyr](https://dplyr.tidyverse.org/) workflow.
See `vignette("dataset", package = "arrow")` for more information on working with Arrow objects via a dplyr interface.

Best practices
==============

TODO
# [Flight best practices](../cpp/flight.html#best-practices)

0 comments on commit 4640e31

Please sign in to comment.