Comments (1)
目前碰到2个致命问题:
- 1 栈不能自动扩容缩容 或导致栈溢出。(例如我使用reqwest,排查了好久才发现是栈默认容量不够)服务挂了,设置的太大又造成内存浪费。强烈建议作者能做到自动扩容(虽然我不清楚其中难度是不是特别大)
- 2 框架不支持阻塞IO自动移动到单独的线程池中。(目前async_std是支持的)。这个问题很玄幻了,开发者当然知道使用协程必须保证你的操作必须非阻塞IO,但是不是所有框架都支持了May的。这不是强迫我吧所有开源框架写一遍支持may吗?。举个例子,我在may mini http中调用 reqwest发起http请求,workers设置为1的情况下,发起一个请求,后续的请求就进不来了。因为被上一个请求阻塞住了。(能接受的最大请求数等于设置的workers数量)
强烈建议作者能做到(阻塞IO自动移动到单独的线程池,虽然我不清楚其中难度是不是特别大)
impl HttpService for HelloWorld {
fn call(&mut self, _req: Request, rsp: &mut Response) -> io::Result<()> {
println!("accept:req");
go!(move ||{
//127.0.0.1:8081这个端口设置了延迟1000秒才返回,模拟阻塞
let resp = reqwest::blocking::get("http://127.0.0.1:8081");
println!("{:?}",resp);
});
rsp.body("Hello, world!");
Ok(())
}
}
struct HelloWorldFac;
impl HttpServiceFactory for HelloWorldFac {
type Service = HelloWorld;
fn new_service(&self) -> Self::Service {
HelloWorld
}
}
fn main() {
may::config().set_workers(1).set_stack_size(0x2000);
env_logger::init();
let server = HelloWorldFac.start("127.0.0.1:8080").unwrap();
server.wait();
}
//main执行后,用浏览器连续5次打开127.0.0.1:8080 只打印了一次 accept:req
http 8081端口代码
use may_minihttp::{HttpServer, HttpService, Request, Response};
use std::io;
use std::thread::sleep;
use std::time::Duration;
/// `HelloWorld` is the *service* that we're going to be implementing to service
/// the HTTP requests we receive.
///
#[derive(Clone)]
struct HelloWorld;
impl HttpService for HelloWorld {
fn call(&mut self, _req: Request, rsp: &mut Response) -> io::Result<()> {
rsp.body("Hello, world!");
sleep(Duration::from_secs(1024));//使用std库睡眠线程,模拟阻塞
Ok(())
}
}
fn main() {
env_logger::init();
let server = HttpServer(HelloWorld).start("127.0.0.1:8081").unwrap();
server.wait();
}
from may.
Related Issues (20)
- support cancel feature gate
- macro select! : Polling a channel that already contained data may not trigger recv HOT 3
- Question about coroutine HOT 2
- `go!` macro allows its arguments to do `unsafe` operations. HOT 1
- No `peek` implementation for `net::TcpStream` HOT 2
- How can May be used for shared-nothing architecture? HOT 3
- The go! macro is unsound HOT 2
- question: way not generator-rs Stack resizes automatically? HOT 4
- Queue needs bounds on its Send/Sync traits HOT 2
- Examples don't compile HOT 2
- about performace.md The description is unfair HOT 3
- 建议参考ants,整个协程池
- `may_http`耗时不符合预期 HOT 5
- 建议参考libco,hook系统函数,减少改造成本 HOT 1
- 问下如何正确地hook系统函数?
- support linux io_uring HOT 1
- unify thread and coroutine io handling
- split io read and write event HOT 1
- How does it actually work
- linux: file descriptor leak in epoll code HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from may.