Skip to content

Implement GRPC protocol.#15111

Merged
vitlibar merged 42 commits intoClickHouse:masterfrom
vitlibar:grpc-protocol
Nov 25, 2020
Merged

Implement GRPC protocol.#15111
vitlibar merged 42 commits intoClickHouse:masterfrom
vitlibar:grpc-protocol

Conversation

@vitlibar
Copy link
Copy Markdown
Member

@vitlibar vitlibar commented Sep 21, 2020

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

Changelog category:

  • New Feature

Changelog entry:
Implement gRPC protocol in ClickHouse.

For the specification of the protocol see clickhouse_grpc.proto

To use the protocol first set grpc_port in the main configuration file, and then you can either write a client in any of the programming languages supported by gRPC by using the provided schema or use the built-in client utils/grpc-client/clickhouse-grpc-client.py. The built-in client is operated very likely to clickhouse-client, for example

utils/grpc-client/clickhouse-grpc-client.py -q "SELECT sum(number) FROM numbers(10)"

cat a.txt | utils/grpc-client/clickhouse-grpc-client.py -q "INSERT INTO temp FORMAT TSV"

and so on. Without parameters it runs the built-in client in the interactive mode.

The implementation of gRPC protocol also supports compression, SSL, getting progress and logs, authentication, parallel queries through the same channel, cancellation of queries, sessions, external tables.

performance comparison


This PR is to finish the work started by @mnkonkova (#10136)

@robot-clickhouse robot-clickhouse added doc-alert pr-feature Pull request with new product feature labels Sep 21, 2020
@vitlibar vitlibar marked this pull request as draft September 21, 2020 22:21
@robot-clickhouse robot-clickhouse added the submodule changed At least one submodule changed in this PR. label Sep 30, 2020
@vitlibar vitlibar force-pushed the grpc-protocol branch 2 times, most recently from 6aed8d0 to 62a14e8 Compare October 4, 2020 04:21
@robot-clickhouse robot-clickhouse removed the submodule changed At least one submodule changed in this PR. label Oct 4, 2020
@vitlibar vitlibar force-pushed the grpc-protocol branch 12 times, most recently from 9790b74 to 8af548f Compare October 7, 2020 16:58
@robot-clickhouse robot-clickhouse added the submodule changed At least one submodule changed in this PR. label Oct 7, 2020
@vitlibar vitlibar force-pushed the grpc-protocol branch 2 times, most recently from 215fda4 to c429ce0 Compare October 7, 2020 22:19
@robot-clickhouse robot-clickhouse added submodule changed At least one submodule changed in this PR. and removed submodule changed At least one submodule changed in this PR. labels Oct 8, 2020
@vitlibar vitlibar force-pushed the grpc-protocol branch 3 times, most recently from 95f5366 to 63e11d8 Compare October 13, 2020 01:27
@vitlibar
Copy link
Copy Markdown
Member Author

test_storage_rabbitmq/test.py::test_rabbitmq_csv_with_delimiter will be fixed in #17311

@vitlibar vitlibar merged commit 08b3707 into ClickHouse:master Nov 25, 2020
add_subdirectory (install)
add_subdirectory (git-import)

#add_subdirectory (grpc-client)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I build it?

Copy link
Copy Markdown
Member Author

@vitlibar vitlibar Nov 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an old test which Maria used to test the grpc protocol for the first time. It cannot be build currently. I didn't fix it because grpc protocol can be invoked directly from python so we don't need a C++ client to test in our integration tests that grpc protocol works.

I didn't remove the sources of the target grpc-client because I was thinking about converting it into C++ client like clickhouse-client, but then I wrote a gRPC client in python, so now I don't think we need the target grpc-client and I suppose we can remove it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this target in #17435

std::unique_ptr<GRPCConnection::GRPC::Stub> stub_;
};

int main(int argc, char** argv)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it's just a test, maybe better move to tests subdirectory somewhere.

<!-- gRPC protocol (see src/Server/grpc_protos/clickhouse_grpc.proto for the API)
<grpc_port>9001</grpc_port>
<grpc>
<enable_ssl>true</enable_ssl> -->
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This --> is strange.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xml doesn't support nested comments.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it looks like you close this comment too early.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about this style?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks surprising to the reader, I'm sure almost no one will understand it from the first glance.

@@ -0,0 +1,13 @@
#pragma once
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accidentially committed?

Copy link
Copy Markdown
Member Author

@vitlibar vitlibar Nov 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in #17435

{
TCP = 1,
HTTP = 2,
GRPC = 3,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about MySQL and PostgreSQL interfaces?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,24 @@
<yandex>
<grpc_port>9001</grpc_port>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe change all ports to 9100?
Because 9001 is often used for second ClickHouse instance if multiple instances are run on the same server.

Copy link
Copy Markdown
Member Author

@vitlibar vitlibar Nov 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in #17435

<grpc_port>9001</grpc_port>
<grpc>
<enable_ssl>true</enable_ssl> -->

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespaces.

@alexey-milovidov
Copy link
Copy Markdown
Member

$ ./clickhouse-grpc-client.py
'list' object has no attribute 'join'

Bye
    <!-- gRPC protocol (see src/Server/grpc_protos/clickhouse_grpc.proto for the API) -->
    <grpc_port>9001</grpc_port>
    <grpc>
        <enable_ssl>false</enable_ssl>
        
        <!-- The following two files are used only if enable_ssl=1
        <ssl_cert_file>/path/to/ssl_cert_file</ssl_cert_file>
        <ssl_key_file>/path/to/ssl_key_file</ssl_key_file> -->
        
        <!-- Whether server will request client for a certificate
        <ssl_require_client_auth>true</ssl_require_client_auth> -->
        
        <!-- The following file is used only if ssl_require_client_auth=1
        <ssl_ca_cert_file>/path/to/ssl_ca_cert_file</ssl_ca_cert_file> -->
        
        <!-- Default compression algorithm (applied if client doesn't specify another algorithm).
             Supported algorithms: none, deflate, gzip, stream_gzip
        <compression>gzip</compression> -->

        <!-- Default compression level (applied if client doesn't specify another level).
             Supported levels: none, low, medium, high
        <compression_level>high</compression_level> -->

        <!-- Send/receive message size limits in bytes. -1 means unlimited
        <max_send_message_size>-1</max_send_message_size>
        <max_receive_message_size>4194304</max_receive_message_size> -->
    </grpc>

@vitlibar
Copy link
Copy Markdown
Member Author

vitlibar commented Nov 26, 2020

$ ./clickhouse-grpc-client.py
'list' object has no attribute 'join'

There was a small mistake in error-handling in this python script, and you have to install grpcio-tools: pip3 install grpcio-tools. Fixed in dbd1366

@alexey-milovidov
Copy link
Copy Markdown
Member

alexey-milovidov commented Nov 28, 2020

Wow, it works!

Does not look polished though:

$ ./clickhouse-grpc-client.py
Connecting to localhost:9100 as user default.
Connected to ClickHouse server version 20.13.1.1 via gRPC protocol in 0.0042569637298583984.
grpc :) SELECT 1
┌─1─┐
│ 1 │
└───┘

Elapsed: 0.002447843551635742 sec.

grpc :) SELECT count() FROM system.numbers
^CCancelling query.
Query was cancelled.
grpc :) SELECT count() FROM test.hits
┌─count()─┐
│ 8873898 │
└─────────┘

Elapsed: 0.002803325653076172 sec.

grpc :) SELECT uniq(*) FROM test.hits
┌─uniq(WatchID, JavaEnable, Title, GoodEvent, EventTime, EventDate, CounterID, ClientIP, ClientIP6, RegionID, UserID, CounterClass, OS, UserAgent, URL, Referer, URLDomain, RefererDomain, Refresh, IsRobot, RefererCategories, URLCategories, URLRegions, RefererRegions, ResolutionWidth, ResolutionHeight, ResolutionDepth, FlashMajor, FlashMinor, FlashMinor2, NetMajor, NetMinor, UserAgentMajor, UserAgentMinor, CookieEnable, JavascriptEnable, IsMobile, MobilePhone, MobilePhoneModel, Params, IPNetworkID, TraficSourceID, SearchEngineID, SearchPhrase, AdvEngineID, IsArtifical, WindowClientWidth, WindowClientHeight, ClientTimeZone, ClientEventTime, SilverlightVersion1, SilverlightVersion2, SilverlightVersion3, SilverlightVersion4, PageCharset, CodeVersion, IsLink, IsDownload, IsNotBounce, FUniqID, HID, IsOldCounter, IsEvent, IsParameter, DontCountHits, WithHash, HitColor, UTCEventTime, Age, Sex, Income, Interests, Robotness, GeneralInterests, RemoteIP, RemoteIP6, WindowName, OpenerName, HistoryLength, BrowserLanguage, BrowserCountry, SocialNetwork, SocialAction, HTTPError, SendTiming, DNSTiming, ConnectTiming, ResponseStartTiming, ResponseEndTiming, FetchTiming, RedirectTiming, DOMInteractiveTiming, DOMContentLoadedTiming, DOMCompleteTiming, LoadEventStartTiming, LoadEventEndTiming, NSToDOMContentLoadedTiming, FirstPaintTiming, RedirectCount, SocialSourceNetworkID, SocialSourcePage, ParamPrice, ParamOrderID, ParamCurrency, ParamCurrencyID, GoalsReached, OpenstatServiceName, OpenstatCampaignID, OpenstatAdID, OpenstatSourceID, UTMSource, UTMMedium, UTMCampaign, UTMContent, UTMTerm, FromTag, HasGCLID, RefererHash, URLHash, CLID, YCLID, ShareService, ShareURL, ShareTitle, ParsedParams.Key1, ParsedParams.Key2, ParsedParams.Key3, ParsedParams.Key4, ParsedParams.Key5, ParsedParams.ValueDouble, IslandID, RequestNum, RequestTry)─┐
│                                                                                                                                                                                                                                                    8904699 │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

Elapsed: 2.339322566986084 sec.

grpc :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Pull request with new product feature submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants