Quantcast
Channel: User Schwern - Stack Overflow
Viewing all articles
Browse latest Browse all 581

Answer by Schwern for Performance of the tokio-postgres driver in rust on simple example

$
0
0

jdbc test shows that 10 users can make 15705 rps (during 120s), and this code - 2850 rps. ConnectionPool is equal. Java better?

It wouldn't be a blanket statement like "Java is better faster", but many factors including the optimization of their Postgres database driver and client library. But without seeing the Java code and knowing it's running on the same hardware, we can't say.


How did 0.134ms turn into 2.2302ms

Correction, its 0.792 ms into 2.2302 ms. The server took 0.658 ms to create a plan for the query and then 0.134 ms executing it.

Planning Time: 0.658 msExecution Time: 0.134 ms

Let's look at what you're actually measuring.

   let start = Instant::now();    let rows = client.query("EXPLAIN ANALYZE SELECT col1 FROM public.test_table WHERE col1 = '15000000'", &[]).await?;    println!("> Query time: {:?}", start.elapsed());

Here you are measuring the time to...

  1. Run client.query.
  2. Send the query to the server.
  3. Wait for the server to receive the query.
  4. The server converts the text of the query into an execution plan. (0.658 ms)
  5. The server executes the query and gets the results. (0.134 ms)
  6. The server sends the result back.
  7. Wait for the client to receive the results.
  8. Convert the result into a Result<Vec<row>>.

The part in bold is what is happening on the server. The rest is either waiting around or things your code is doing, that accounts for the other 1.44 ms. Yes, there is network latency on even a local server.

why did the iteration take 2.3609ms

Because computers take time to do things.

    let start_time_1 = Instant::now();    for row in rows {        let value: &str = row.get(0);        println!("{}", value);    }    println!("> Loop time: {:?} / Full time: {:?}", start_time_1.elapsed(), start.elapsed());
  1. Allocate row.
  2. Enter the loop.
  3. Call Row::get.
  4. Print it.
  5. Wait for the print to complete. (Printing takes time. It's I/O just like writing to a file.)
  6. Exit the loop.

Why did that take 2.3609ms? I can't say. You could profiling your code to find the bottleneck.


Viewing all articles
Browse latest Browse all 581

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>