IRL2 / nanover-server-py

https://irl2.github.io/nanover-docs/#
Other
0 stars 1 forks source link

~20fps bottleneck in rust and/or python server? #182

Closed Ragzouken closed 2 weeks ago

Ragzouken commented 4 months ago

Couldn't replicate with either rust (nanotube, frame/force interval set to 1, include forces and velocities) or python:

import time
import grpc
import numpy

from nanover.protocol.trajectory import TrajectoryServiceStub, GetFrameRequest

def test_fps():
    channel = grpc.insecure_channel("localhost:38801")
    stub = TrajectoryServiceStub(channel)
    request = GetFrameRequest()
    stream = stub.SubscribeLatestFrames(request)

    times = []
    for frame in stream:
        times.append(time.perf_counter())
        if len(times) % 50 == 0:
            diffs = numpy.diff(times)
            avg = sum(diffs) / len(diffs)
            print(f"{avg}s -- {1/avg}Hz")
            times = []

test_fps()
Ragzouken commented 4 months ago

Can get 30fps but the frames weren't distinct--like frames themselves not updating at 30fps

Ragzouken commented 3 months ago

Used this to verify that frames are being received at 30fps and that the positions are changing between each of those frames. For the rust server I'm getting 99-100% of position values changing, each by at least 2e-7, with each frame evenly spaced.

import time
import grpc
import numpy as np

from nanover.omni.playback import PlaybackSimulation
from nanover.protocol.trajectory import TrajectoryServiceStub, GetFrameRequest
from nanover.trajectory import FrameData

def test_frames():
    playback = PlaybackSimulation.from_paths(["test.traj"])
    playback.load()

    channel = grpc.insecure_channel("localhost:38801")
    stub = TrajectoryServiceStub(channel)
    request = GetFrameRequest()
    stream = stub.SubscribeLatestFrames(request)

    times = []
    times_all = []

    try:
        prev = None
        for message in stream:
            frame = FrameData(message.frame)
            next = np.array(frame.particle_positions)
            if prev is not None:
                diff = np.abs(next - prev)
                min = np.min(diff)
                max = np.max(diff)

                value_count = np.size(diff)
                change_count = np.count_nonzero(diff)
                changed_fraction = change_count / value_count

                print(f"{changed_fraction:.0%} of values changed, min change: {min:.1g}, max change: {max:.1g}")
            else:
                print(len(frame.particle_positions) * 3)
            prev = next

            times.append(time.perf_counter())
            times_all.append(times[-1])
            if len(times) % 30 == 0:
                diffs = np.diff(times)
                avg = sum(diffs) / len(diffs)
                print(f"{avg}s -- {1 / avg}Hz, {np.min(diffs)}")
                times = []
    except KeyboardInterrupt:
        diffs = np.diff(times_all)
        print(diffs)

test_frames()
Ragzouken commented 2 weeks ago

We'll consider this a non-issue unless it comes up again.