Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite clickhouse-test to use python clickhouse_driver #29856

Merged

Conversation

azat
Copy link
Collaborator

@azat azat commented Oct 7, 2021

Pros:

  • Using native protocol over executing binaries is always better
  • clickhouse-client in debug build takes almost a second to execute simple SELECT 1
    and clickhouse-test requires ~5 queries at start (determine some
    flags, zk, alive, create database)

Notes:

  • FORMAT Vertical had been replaced with printing of pandas.DataFrame

And after this patch tiny tests work with the speed of the test, and
does not requires +-5 seconds of bootstrapping.

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

@robot-clickhouse robot-clickhouse added the pr-not-for-changelog This PR should not be mentioned in the changelog label Oct 7, 2021
@azat
Copy link
Collaborator Author

azat commented Oct 7, 2021

Can some one add force test label please? (it requires updating of fast test image which is not built per-PR AFAIK)

@nikitamikhaylov nikitamikhaylov added the force tests The label does nothing, NOOP, None, nil label Oct 7, 2021
@nikitamikhaylov
Copy link
Member

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Oct 7, 2021

Command update: success

Branch already up to date

@alexey-milovidov
Copy link
Member

But it does not test clickhouse-client.
It's worth doing for debug and sanitizers builds.

@azat
Copy link
Collaborator Author

azat commented Oct 7, 2021

@alexey-milovidov this PR converts only service use of clickhouse-client i.e. to:

  • run show processlist
  • to health check (simple select 1 or select {test_name})
  • create database for tests

Every .sql test that was started using clickhouse-client will still use it.

@azat azat marked this pull request as draft October 7, 2021 21:09
Pros:
- Using native protocol over executing binaries is always better
- `clickhouse-client` in debug build takes almost a second to execute simple `SELECT 1`
  and `clickhouse-test` requires ~5 queries at start (determine some
  flags, zk, alive, create database)

Notes:
- `FORMAT Vertical` had been replaced with printing of `pandas.DataFrame`

And after this patch tiny tests work with the speed of the test, and
does not requires +-5 seconds of bootstrapping.
@azat azat force-pushed the clickhouse-test-python-client branch from 683dfc7 to e2d6698 Compare October 7, 2021 21:09
@amosbird
Copy link
Collaborator

amosbird commented Oct 8, 2021

How about adding an option to run tests with clickhouse_driver as this is only useful for developers.

@alexey-milovidov
Copy link
Member

this PR converts only service use of clickhouse-client

Ok.

@azat
Copy link
Collaborator Author

azat commented Oct 8, 2021

How about adding an option to run tests with clickhouse_driver as this is only useful for developers.

This will too strange. Then, I would prefer to just leave it as-is (i.e. close this PR).
@amosbird Why do you think that separate code path is required for this?

I've converted it to python driver to make it faster since executing binaries (even from release build) will be always slower then simply connect+send+recv (i.e. native protocol).
My use case, once I've added some test I want to check it, and I'm waiting for clickhouse-test to do some checks that takes +-5 seconds with debug build.

@alexey-milovidov
Copy link
Member

alexey-milovidov commented Oct 8, 2021

I've converted it to python driver to make it faster since executing binaries (even from release build) will be always slower then simply connect+send+recv (i.e. native protocol).

Ok. I think it's worth doing.
But let's also improve the startup time of clickhouse-client (in separate PR).

for i in {1..10000}; do clickhouse-local --query "SELECT 1"; done

  • it's spending time in initializing DateLUT - for what?

@amosbird
Copy link
Collaborator

amosbird commented Oct 8, 2021

Why do you think that separate code path is required for this?

I missed this reply "this PR converts only service use of clickhouse-client" and thought it was to replace clickhouse-client for .sql tests)

@azat azat marked this pull request as ready for review October 8, 2021 22:43
@amosbird
Copy link
Collaborator

amosbird commented Oct 9, 2021

Btw, why don't we just use HTTP for this purpose instead?

@azat
Copy link
Collaborator Author

azat commented Oct 9, 2021

Btw, why don't we just use HTTP for this purpose instead?

I don't see any benefits in using HTTP instead of TCP.
Plus you need to parse it (since we don't only need to execute queries, and check return values, but also there are things like show processlist)

@azat
Copy link
Collaborator Author

azat commented Oct 9, 2021

BTW looks like everything related had been passed!

Fast test — Cannot install or start ClickHouse

Requires image update (@alesapin I guess it will be done automatically after merge?).

@azat
Copy link
Collaborator Author

azat commented Oct 9, 2021

Btw, why don't we just use HTTP for this purpose instead?

Ok, I haven't understand that clear enough.

@amosbird is right, HTTP interface can be also used instead of clickhouse-driver (python).

Cons:

  • one more extra dependency

Pros:

  • has better error handling (i.e. defines lots of exceptions for various kind of errors, and also provides lots of predefined error codes)
  • provide better API for reading (streaming and so on), but it is not used right now
  • it is already used for performance tests, so the cost of adding this "extra dependency" should be minor (although I guess not every developer runs performance tests by themselves, but they do run stateless tests for sure)

So maybe someone else has some opinion on this?

@alexey-milovidov
Copy link
Member

I don't have stong opinion on that - let's use what will be more convenient.

@azat
Copy link
Collaborator Author

azat commented Oct 9, 2021

Integration tests (asan) — fail: 3, passed: 1585, flaky: 4
Integration tests (release) — fail: 3, passed: 1588, flaky: 3
Integration tests (thread) — fail: 5, passed: 1583, flaky: 5

Also note, that this should make integration tests green.

@alexey-milovidov alexey-milovidov merged commit 268c155 into ClickHouse:master Oct 9, 2021
@azat
Copy link
Collaborator Author

azat commented Oct 9, 2021

Some numbers:

  • fasttest: before 11min/14min, after 9min/12min -- no benefit
  • stateless debug: no benefit
SELECT DISTINCT
    check_duration_ms,
    if(report_url LIKE '%268c155b7d4b15524219ea48cf228bf140cf9cdd%', 'python-requests', '') AS mr
FROM checks
WHERE (check_start_time > today()) AND (pull_request_number = 0) AND (report_url LIKE '%stateless_tests_(debug)%')
ORDER BY check_start_time ASC
FORMAT PrettyCompactMonoBlock

Query id: e9252c81-fe1c-4387-b62c-1a4c69e72715

┌─check_duration_ms─┬─mr──────────────┐
│           9168779 │                 │
│          11118219 │                 │
│           7965240 │ python-requests │
│           8240968 │                 │
│           8505889 │                 │
│           8503848 │                 │
│           8318323 │                 │
│           8066711 │                 │
└───────────────────┴─────────────────┘
  • under sanitizers stateless tests looks a little bit faster, but no significant difference.
SELECT DISTINCT
    check_duration_ms,
    if(report_url LIKE '%268c155b7d4b15524219ea48cf228bf140cf9cdd%', 'python-requests', '') AS mr
FROM checks
WHERE (check_start_time > today()) AND (pull_request_number = 0) AND (report_url LIKE '%stateless_tests_(memory)%')
ORDER BY check_start_time ASC
FORMAT PrettyCompactMonoBlock

Query id: bc1993e5-413f-4d6a-86e2-66e0c1465efb

┌─check_duration_ms─┬─mr──────────────┐
│           7283462 │                 │
│           7491509 │                 │
│           7040965 │ python-requests │
│           6817031 │                 │
│           6866696 │                 │
│           6504630 │                 │
│           6624146 │                 │
│           6728470 │                 │
└───────────────────┴─────────────────┘

@azat azat deleted the clickhouse-test-python-client branch October 9, 2021 22:25
@tavplubix
Copy link
Member

$ ./clickhouse-test  "01921_concurrent|992|993|1154|1593|1079"
Traceback (most recent call last):
  File "./clickhouse-test", line 38, in <module>
    import pandas
ModuleNotFoundError: No module named 'pandas'`

Should we fallback to using clickhouse-test if pandas or clickhouse_driver are not installed (just like we do it for termcolor and jinja)?

@tavplubix
Copy link
Member

Another issue:

$ ./clickhouse-test  "01921_concurrent|992|993|1154|1593|1079"
Using queries from 'queries' directory
Using clickhouse-client as client program (expecting split build)
Connecting to ClickHouse server... OK

Running 17 stateless tests (MainProcess).

01921_concurrent_ttl_and_normal_merges_zookeeper_long:                  Unknown setting log_comment. Skipping
[ OK ]
01593_concurrent_alter_mutations_kill_many_replicas_long:               Unknown setting log_comment. Skipping
[ OK ]

https://github.com/mymarilyn/clickhouse-driver/blob/9ce201c0689ab04bf85660da78c640dec8c15355/clickhouse_driver/settings/writer.py#L24

@azat
Copy link
Collaborator Author

azat commented Oct 11, 2021

Should we fallback to using clickhouse-test if pandas or clickhouse_driver are not installed (just like we do it for termcolor and jinja)?

Have a fallback for this code looks error prone and does not worth it to me.

P.S. I also think that fallback for jinja is extra complexity that does not worth it.
It is ok (to me) to have a fallback for termcolor since it is not a major functionality of clickhouse-test, unlike templated tests.

Unknown setting log_comment. Skipping

@tavplubix what version of clickhouse-driver do you have? (It should not produce such warnings after mymarilyn/clickhouse-driver#142)

Actually I've talked with @alesapin and he said his strong objections against using clickhouse-driver for clickhouse-test, so I'm planning to rewrite it to simple python requests (and using HTTP interface).

@alexey-milovidov
Copy link
Member

Actually I've talked with @alesapin and he said his strong objections against using clickhouse-driver for clickhouse-test, so I'm planning to rewrite it to simple python requests (and using HTTP interface).

+1.

azat added a commit to azat/ClickHouse that referenced this pull request Oct 12, 2021
Before ClickHouse#29856 `CREATE DATABASE` overwrites it.

Reported-by: @amosbird
Comment on lines -576 to -577
if args.replicated_database:
drop_database_query += " ON CLUSTER test_cluster_database_replicated"
Copy link
Member

Choose a reason for hiding this comment

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

These lines should not have been removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
force tests The label does nothing, NOOP, None, nil pr-not-for-changelog This PR should not be mentioned in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants