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

investigate why cli is so slow #15373

Closed
kelwang opened this issue Oct 9, 2019 · 7 comments
Closed

investigate why cli is so slow #15373

kelwang opened this issue Oct 9, 2019 · 7 comments

Comments

@kelwang
Copy link
Contributor

kelwang commented Oct 9, 2019

with the influxd locally.
compare the cli time and api time. have 2 orgs
curl http://localhost:9999/api/v2/orgs took 0.02 secs.
run

influx org find|gnomon

got

2.5534s   ID			Name
   0.0006s   60b45ab5d3826209	org2
   0.0011s   b3ef3f1a0e3cebc0	org1
   0.0002s

   Total   2.5562s

almost all command took at least 2.5 sec.

exp: influx -h|gnomon

2.7557s   Influx Client
   0.0014s
   0.0001s   Usage:
   0.0001s     influx [flags]
   0.0001s     influx [command]
   0.0001s
   0.0001s   Available Commands:
   0.0001s     auth        Authorization management commands
   0.0001s     bucket      Bucket management commands
   0.0001s     help        Help about any command
   0.0001s     org         Organization management commands
   0.0001s     ping        Check the InfluxDB /health endpoint
   0.0001s     query       Execute a Flux query
   0.0001s     repl        Interactive REPL (read-eval-print-loop)
   0.0001s     setup       Setup instance with initial user, org, bucket
   0.0001s     task        Task management commands
   0.0001s     user        User management commands
   0.0001s     write       Write points to InfluxDB
   0.0000s
   0.0000s   Flags:
   0.0000s     -h, --help           Help for the influx command
   0.0000s         --host string    HTTP address of Influx (default "http://loca
             lhost:9999")
   0.0000s     -t, --token string   API token to be used throughout client calls
   0.0010s   Use "influx [command] --help" for more information about a command.
   0.0001s   Use "influx [command] --help" for more information about a command.

     Total   2.7628s
@Srokap
Copy link

Srokap commented Nov 2, 2019

I am trying to run influxdb on raspberrypi and I have some ridiculously slow cli client startup, it might be related. The http interface is fast and snappy, but just calling influx takes it something like 1 min to connect to localhost. During that time the client process maxes out on CPU.

$ influx | gnomon
  74.4769s   Connected to http://localhost:8086 version 1.7.9

Establishing socket itself is not a problem

$ time nc -v localhost 8086
Connection to localhost 8086 port [tcp/*] succeeded!
^C

real    0m0.276s
user    0m0.001s
sys     0m0.024s

I wonder if we have problem with similar step that is more prominent on my low-resource machine.

$ influx -h | gnomon
  72.4968s   Usage of influx:
   0.0116s     -version
   0.0028s          Display the version and exit.
   0.0020s     -host 'host name'
   0.0023s          Host to connect to.
   0.0016s     -port 'port #'
   0.0016s          Port to connect to.
   0.0018s     -socket 'unix domain socket'
   0.0018s          Unix socket to connect to.
   0.0016s     -database 'database name'
   0.0010s          Database to connect to the server.
   0.0017s     -password 'password'
   0.0009s         Password to connect to the server.  Leaving blank will prompt for password (--password '').
   0.0009s     -username 'username'
   0.0009s          Username to connect to the server.
   0.0013s     -ssl
   0.0010s           Use https for requests.
   0.0009s     -unsafeSsl
   0.0009s           Set this when connecting to the cluster using https and not use SSL verification.
   0.0009s     -execute 'command'
   0.0013s          Execute command and quit.
   0.0018s     -type 'influxql|flux'
   0.0015s          Type specifies the query language for executing commands or when invoking the REPL.
   0.0013s     -format 'json|csv|column'
   0.0016s          Format specifies the format of the server responses:  json, csv, or column.
   0.0031s     -precision 'rfc3339|h|m|s|ms|u|ns'
   0.0046s          Precision specifies the format of the timestamp:  rfc3339, h, m, s, ms, u or ns.
   0.0019s     -consistency 'any|one|quorum|all'
   0.0012s          Set write consistency level: any, one, quorum, or all
   0.0010s     -pretty
   0.0011s          Turns on pretty print for the json format.
   0.0009s     -import
   0.0012s          Import a previous database export from file
   0.0014s     -pps
   0.0016s          How many points per second the import will allow.  By default it is zero and will not throttle im
             porting.
   0.0014s     -path
   0.0020s          Path to file to import
   0.0014s     -compressed
   0.0013s          Set to true if the import file is compressed
   0.0015s
   0.0018s   Examples:
   0.0016s
   0.0010s       # Use influx in a non-interactive mode to query the database "metrics" and pretty print json:
   0.0011s       $ influx -database 'metrics' -execute 'select * from cpu' -format 'json' -pretty
   0.0008s
   0.0009s       # Connect to a specific database on startup and set database context:
   0.0373s       $ influx -database 'metrics' -host 'localhost' -port '8086'
   0.0058s

     Total   72.6697s

We seem to use different versions, but general behavior seems the same.

$ influx -version | gnomon
  73.0272s   InfluxDB shell version: 1.7.9
   0.0117s

     Total   73.0456s

@kelwang
Copy link
Contributor Author

kelwang commented Nov 15, 2019

So seems like the issue comes from a blank import of
_ github.com/influxdata/influxdb/query/builtin

which will also blank import
_ "github.com/influxdata/flux/stdlib" // Import the stdlib
_ "github.com/influxdata/influxdb/query/stdlib" // Import the stdlib

by removing query.go, repl.go, the cli can be reduced to 7-12 miliseconds

    $ influx -h|gnomon
   0.0049s   Influx Client
   0.0004s
   0.0001s   Usage:
   0.0001s     influx [flags]
   0.0000s     influx [command]
   0.0001s
   0.0001s   Available Commands:
   0.0000s     auth        Authorization management commands
   0.0001s     bucket      Bucket management commands
   0.0001s     delete      Delete points from influxDB
   0.0001s     help        Help about any command
   0.0000s     org         Organization management commands
   0.0000s     ping        Check the InfluxDB /health endpoint
   0.0001s     setup       Setup instance with initial user, org, bucket
   0.0001s     task        Task management commands
   0.0000s     user        User management commands
   0.0000s     write       Write points to InfluxDB
   0.0000s
   0.0000s   Flags:
   0.0000s     -h, --help           Help for the influx command
   0.0000s         --host string    HTTP address of Influx (default "http://loc
   0.0000s         --local          Run commands locally against the filesystem
   0.0001s     -t, --token string   API token to be used throughout client call
             s
   0.0000s
   0.0016s   Use "influx [command] --help" for more information about a command
             .
   0.0003s

     Total   0.0097s

compare to

   $ influx -h|gnomon
   3.6426s   Influx Client
   0.0021s
   0.0001s   Usage:
   0.0001s     influx [flags]
   0.0001s     influx [command]
   0.0002s
   0.0001s   Available Commands:
   0.0000s     auth        Authorization management commands
   0.0000s     bucket      Bucket management commands
   0.0000s     delete      Delete points from influxDB
   0.0000s     help        Help about any command
   0.0000s     org         Organization management commands
   0.0000s     ping        Check the InfluxDB /health endpoint
   0.0000s     setup       Setup instance with initial user, org, bucket
   0.0000s     task        Task management commands
   0.0000s     user        User management commands
   0.0000s     write       Write points to InfluxDB
   0.0001s
   0.0003s   Flags:
   0.0001s     -h, --help           Help for the influx command
   0.0000s         --host string    HTTP address of Influx (default "http://loc
   0.0001s         --local          Run commands locally against the filesystem
   0.0001s     -t, --token string   API token to be used throughout client call
             s
   0.0001s
   0.0029s   Use "influx [command] --help" for more information about a command
             .
   0.0002s

     Total   3.6513s

I think query is simple to fix by sending a tcp request to influxd. For repl, @nathanielc, @jsternberg, what do you think about making a web socket inside influxd?

cc @russorat

@nathanielc
Copy link
Contributor

@kelwang An issue like this was recently fixed #15441 Are you running off latest master?

No network connection is being made to influxd in this case.

@kelwang
Copy link
Contributor Author

kelwang commented Nov 16, 2019

nice, close it

@kelwang kelwang closed this as completed Nov 16, 2019
@dandv
Copy link
Contributor

dandv commented Feb 11, 2020

Did this fix make it into v1.7.10? I'm still seeing an extremely slow CLI on v1.7.10 - 30 seconds just to display the version:

$ time influx -version
InfluxDB shell version: 1.7.10

real	0m29.483s
user	0m23.901s
sys	0m0.321s

@russorat
Copy link
Contributor

@dandv thanks for commenting here. I don't see any indication that this was backported. Let me try to track this down.

@russorat
Copy link
Contributor

Sorry, It looks like it was supposed to happen in #16192 but there were a lot of conflicts and was bumped to 1.7.11.

I'm closing this again. Please track the progress in issue #16192

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

No branches or pull requests

5 participants