Commit 69a394a
authored
Do not block main server thread when launching streaming threads (#5)
Instead, handle streaming queue in a new thread (which serialises writes to the connection socket, and handlers errors such as IOError, Errno::EPIPE triggering callbacks.
This is so that the server's request thread (ie Puma) can be quickly returned to the pool.
Servers like Falcon (fibers instead of threads) should not have this problem, but they should still work fine with this (they will spawn an extra fiber, but that should be cheap).
Possible issues:
This change decouples the server's thread pool from Datastar's streaming threads, which ATM are unbounded (an app with long-lived streams could potentially spawn thousands of threads even if the server is configured with a limited pool.
This can be problematic, because:
* The server can run out of resourced
* If the streams rely on services such as database connections, they could quickly drain those connection pools.
Possible solution: provide configuration for a separate, Datastar-specific thread-pool so that it can be tweaked as per available resources (such as database pools)1 parent 5bb5eda commit 69a394a
4 files changed
Lines changed: 76 additions & 21 deletions
File tree
- lib/datastar
- spec
- support
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
288 | | - | |
| 288 | + | |
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
| |||
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
| 316 | + | |
316 | 317 | | |
317 | 318 | | |
318 | | - | |
| 319 | + | |
319 | 320 | | |
320 | 321 | | |
321 | 322 | | |
322 | 323 | | |
323 | 324 | | |
324 | 325 | | |
325 | 326 | | |
326 | | - | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
327 | 333 | | |
328 | 334 | | |
329 | 335 | | |
| |||
332 | 338 | | |
333 | 339 | | |
334 | 340 | | |
335 | | - | |
| 341 | + | |
| 342 | + | |
336 | 343 | | |
337 | | - | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
338 | 352 | | |
339 | 353 | | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
340 | 359 | | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | 360 | | |
345 | 361 | | |
346 | 362 | | |
347 | | - | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
348 | 376 | | |
349 | 377 | | |
350 | 378 | | |
351 | 379 | | |
352 | | - | |
| 380 | + | |
353 | 381 | | |
354 | 382 | | |
355 | 383 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| 6 | + | |
6 | 7 | | |
7 | | - | |
| 8 | + | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| 13 | + | |
| 14 | + | |
11 | 15 | | |
12 | 16 | | |
13 | 17 | | |
14 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
15 | 22 | | |
16 | 23 | | |
17 | 24 | | |
18 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
19 | 34 | | |
20 | 35 | | |
21 | 36 | | |
| |||
407 | 422 | | |
408 | 423 | | |
409 | 424 | | |
| 425 | + | |
| 426 | + | |
410 | 427 | | |
411 | 428 | | |
412 | 429 | | |
| |||
448 | 465 | | |
449 | 466 | | |
450 | 467 | | |
451 | | - | |
452 | | - | |
| 468 | + | |
| 469 | + | |
453 | 470 | | |
454 | 471 | | |
455 | 472 | | |
456 | 473 | | |
457 | 474 | | |
458 | 475 | | |
459 | 476 | | |
| 477 | + | |
| 478 | + | |
460 | 479 | | |
461 | 480 | | |
462 | 481 | | |
| |||
467 | 486 | | |
468 | 487 | | |
469 | 488 | | |
470 | | - | |
471 | | - | |
| 489 | + | |
472 | 490 | | |
473 | 491 | | |
474 | 492 | | |
| |||
496 | 514 | | |
497 | 515 | | |
498 | 516 | | |
| 517 | + | |
499 | 518 | | |
500 | 519 | | |
501 | 520 | | |
| |||
520 | 539 | | |
521 | 540 | | |
522 | 541 | | |
523 | | - | |
524 | | - | |
| 542 | + | |
525 | 543 | | |
526 | 544 | | |
| 545 | + | |
527 | 546 | | |
528 | 547 | | |
529 | 548 | | |
| |||
536 | 555 | | |
537 | 556 | | |
538 | 557 | | |
539 | | - | |
540 | | - | |
| 558 | + | |
541 | 559 | | |
542 | 560 | | |
| 561 | + | |
543 | 562 | | |
544 | 563 | | |
545 | 564 | | |
| |||
555 | 574 | | |
556 | 575 | | |
557 | 576 | | |
| 577 | + | |
558 | 578 | | |
559 | 579 | | |
560 | 580 | | |
| |||
570 | 590 | | |
571 | 591 | | |
572 | 592 | | |
| 593 | + | |
573 | 594 | | |
574 | 595 | | |
575 | 596 | | |
| |||
584 | 605 | | |
585 | 606 | | |
586 | 607 | | |
| 608 | + | |
587 | 609 | | |
588 | 610 | | |
589 | 611 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| |||
0 commit comments