mirror of
https://github.com/samsonjs/vibetunnel.git
synced 2026-04-21 13:55:54 +00:00
smaller buffer and flush
This commit is contained in:
parent
37b36ab801
commit
12ce2cd834
2 changed files with 17 additions and 7 deletions
|
|
@ -137,6 +137,11 @@ func (w *StreamWriter) writeEvent(eventType EventType, data []byte) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Immediately flush if the writer supports it for real-time output
|
||||
if flusher, ok := w.writer.(interface{ Flush() error }); ok {
|
||||
flusher.Flush()
|
||||
}
|
||||
|
||||
// Schedule sync instead of immediate sync for better performance
|
||||
w.scheduleBatchSync()
|
||||
|
||||
|
|
@ -150,8 +155,8 @@ func (w *StreamWriter) scheduleFlush() {
|
|||
w.flushTimer.Stop()
|
||||
}
|
||||
|
||||
// Set up new timer for 1ms flush delay for better real-time performance
|
||||
w.flushTimer = time.AfterFunc(1*time.Millisecond, func() {
|
||||
// Set up immediate flush for real-time performance
|
||||
w.flushTimer = time.AfterFunc(0, func() {
|
||||
w.mutex.Lock()
|
||||
defer w.mutex.Unlock()
|
||||
|
||||
|
|
@ -186,6 +191,11 @@ func (w *StreamWriter) scheduleFlush() {
|
|||
return
|
||||
}
|
||||
|
||||
// Immediately flush if the writer supports it for real-time output
|
||||
if flusher, ok := w.writer.(interface{ Flush() error }); ok {
|
||||
flusher.Flush()
|
||||
}
|
||||
|
||||
// Schedule sync instead of immediate sync for better performance
|
||||
w.scheduleBatchSync()
|
||||
|
||||
|
|
@ -203,8 +213,8 @@ func (w *StreamWriter) scheduleBatchSync() {
|
|||
w.syncTimer.Stop()
|
||||
}
|
||||
|
||||
// Schedule sync after 1ms for better real-time performance
|
||||
w.syncTimer = time.AfterFunc(1*time.Millisecond, func() {
|
||||
// Schedule immediate sync for real-time performance
|
||||
w.syncTimer = time.AfterFunc(0, func() {
|
||||
if w.needsSync {
|
||||
if file, ok := w.writer.(*os.File); ok {
|
||||
if err := file.Sync(); err != nil {
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ func fdIsSet(set *syscall.FdSet, fd int) bool {
|
|||
// pollWithSelect polls multiple file descriptors using select
|
||||
func (p *PTY) pollWithSelect() error {
|
||||
// Buffer for reading
|
||||
buf := make([]byte, 32*1024)
|
||||
buf := make([]byte, 4*1024) // 4KB buffer for more responsive output
|
||||
|
||||
// Get file descriptors
|
||||
ptyFd := int(p.pty.Fd())
|
||||
|
|
@ -106,8 +106,8 @@ func (p *PTY) pollWithSelect() error {
|
|||
fds = append(fds, controlFd)
|
||||
}
|
||||
|
||||
// Wait for activity with 100ms timeout for better responsiveness
|
||||
ready, err := selectRead(fds, 100*time.Millisecond)
|
||||
// Wait for activity with 10ms timeout for real-time responsiveness
|
||||
ready, err := selectRead(fds, 10*time.Millisecond)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] select error: %v", err)
|
||||
return err
|
||||
|
|
|
|||
Loading…
Reference in a new issue