togetheros / cicada Goto Github PK
View Code? Open in Web Editor NEW🚀 Fast lightweight HTTP service framework.
Home Page: https://crossoverjie.top/categories/cicada/
License: Apache License 2.0
🚀 Fast lightweight HTTP service framework.
Home Page: https://crossoverjie.top/categories/cicada/
License: Apache License 2.0
我的机器是macbook pro,4C 16G配置,我在jmeter上打到3000并发就有大量请求处理失败了,方便问下想打到10w并发需要怎么设置,谢谢。
CicadaSetting.java类中setting方法中
CicadaBeanManager.getInstance().initBean(rootPath);
这里的rootPath应该是packageName吧?(通过clazz对象获取)
这个获取IOC容器是不是有点复杂了
/**
* get custom route bean
* @return
* @throws Exception
*/
public static Class<?> getCustomRouteBean() throws Exception {
List<Class<?>> classList = new ArrayList<>();
Set<Class<?>> classes = getCustomRouteBeanClasses(BASE_PACKAGE) ;
for (Class<?> aClass : classes) {
if (aClass.getInterfaces().length == 0){
continue;
}
if (aClass.getInterfaces()[0] != CicadaBeanFactory.class){
continue;
}
classList.add(aClass) ;
}
if (classList.size() > 2){
throw new CicadaException(StatusEnum.DUPLICATE_IOC);
}
if (classList.size() == 2){
Iterator<Class<?>> iterator = classList.iterator();
while (iterator.hasNext()){
if (iterator.next()== CicadaDefaultBean.class){
iterator.remove();
}
}
}
return classList.get(0);
}
使用时也仅仅:
public void init(String packageName) throws Exception {
Map<String, Class<?>> cicadaAction = ClassScanner.getCicadaAction(packageName);
Class<?> bean = ClassScanner.getCustomRouteBean();
cicadaBeanFactory = (CicadaBeanFactory) bean.newInstance() ;
for (Map.Entry<String, Class<?>> classEntry : cicadaAction.entrySet()) {
Object instance = classEntry.getValue().newInstance();
cicadaBeanFactory.register(instance) ;
}
}
建议:
getCustomRouteBean 逻辑不用这么复杂,直接返回CicadaIoc.class
命名也不应该是getCustomRouteBean ,而应该是getIocFactory
Hi, in your code HttpDispatcher:105, is it better to put the cleaning code to the ChannelFutureListener of ctx.writeAndFlush(response);
?
以下拦截器接口:
public interface CicadaInterceptor {
/**
* before
* @param param
*/
void before(Param param) ;
/**
* after
* @param param
*/
void after(Param param) ;
}
如果要在拦截器中驳回请求,
这个接口如何支持,或者有相关的适配器?
或者将接口改成:
public interface CicadaInterceptor {
/**
* before
* @param param
*/
boolean before(Param param) ;
/**
* after
* @param param
*/
void after(Param param) ;
}
会不会更好?
而且感觉拦截器只接受Param参数,应该是不够用的。
1.建议使用SimpleChannelInboundHandler取代ChannelInboundHandlerAdapter,避免请求消息体类型判断,方便后续扩展自定义的第三方的http请求
2.因为请求是无状态的,建议使用单例的模式,避免请求量大的时候创建过多的handler去处理请求消息
例子:
`public class RequestHandlerHandler extends SimpleChannelInboundHandler {
public static final IMHandler INSTANCE = new IMHandler();
private Map<Byte, SimpleChannelInboundHandler<? extends Packet>> handlerMap;
private IMHandler() {
handlerMap = new HashMap<>();
handlerMap.put(MESSAGE_REQUEST, MessageRequestHandler.INSTANCE);
handlerMap.put(LOGIN_REQUEST, LoginRequestHandler.INSTANCE);
}
@Override
protected void channelRead0(ChannelHandlerContext ctx, Packet packet) throws Exception {
handlerMap.get(packet.getCommand()).channelRead(ctx, packet);
}
}`
Interceptor interceptor = (Interceptor) annotation;
interceptorMap.put(interceptor.order(), cls);
希望能修复
读取配置文件的操作能不能从action里面抽离,action里面只写业务逻辑,读取配置文件的操作在整个框架启动的时候实现。
搞个框架的生命周期啥的,可能实现起来相当困难,大佬可以酌情忽略
HttpDispatcher是阻塞式的,WorkAction中如果发起异步任务的话会有大麻烦。
不打开keepalive的情况下,像http这种短连接协议,很大程度上是没有用到nio的特性的。也就是说,io线程数决定并发数,在netty中也就是work线程,NioEventLoopGroup默认的线程是cpu*2,对于HTTP服务器来说是远远不够的。将这个值做成用户可配置的是否会更好?
netty 处理请求消息的handler中基于注解@CicadaAction与@interceptor可以放在初始化阶段扫描,避免第一次请求时初始化,handler尽量至保证业务逻辑处理
Describe the solution you'd like
Boss线程数好像设置有误
private static final int BOSS_SIZE = Runtime.getRuntime().availableProcessors() * 2; private static EventLoopGroup boss = new NioEventLoopGroup(BOSS_SIZE);
Netty 的服务器端的 acceptor 阶段, 没有使用到多线程,
服务器端的 ServerSocketChannel 只绑定到了 bossGroup 中的一个线程, 在调用 Java NIO 的 Selector.select 处理客户端的连接请求时, 实际上是在一个线程中的, 所以对只有一个服务的应用来说, bossGroup 设置多个线程是没有什么作用的
Is your feature request related to a problem? Please describe.
Action
类是通过实现WorkAction
接口的execute()
方法来实现路由的,这样一个类只能实现一个路由,实际使用起来未必会有点麻烦吧
Describe the solution you'd like
如果能够像spring mvc那样一个controller下可以有多个RequestMapping就比较好吧。
Describe alternatives you've considered
Action
类不用实现WorkAction
接口,直接扫描所有被@CicadaAction
注解的类,然后再反射获取这个类中被@CicadaExcute
注解的方法(我看到有@CicadaExcute
这个注解,但没有被使用,是否是准备用于这方面的?),再反射调用这个方法。
不过这样的话就是比较难约束用户对于被@CicadaExcute
注解的方法传入的参数,我想到有两种方式约束:
CicadaContext
和Param
,否则就抛出异常CicadaContext
或Param
就在invoke的时候传进去,如果没有就不传,如果有其他参数就传null值。通过注解也不需要手工去注册,启动时自动扫描需要注册实例化的bean,直接加载到内存,使用方便。
Is your feature request related to a problem? Please describe.
目前的拦截器只能处理一个拦截任务。
Describe the solution you'd like
利用责任链模式支持灵活拓展
性能测试是用什么跑的?
飞机
HttpDispter是实际的业务处理代码,会有阻塞操作
怎么返回纯字符串内容不要JSON格式?
RingBufferWheel 请问如何保证最后一个 Task 在 调用了 stop(false) 后还能被执行
写了半天。。。最终发现除了get 其他的都拿不到参数....
Describe the bug
if i set my project structure like this:
├── src/main/java
├── ├──MainStart.java //app start
i didn't set the package path, then,got this error:
ThreadLocalHolder.setLocalTime(System.currentTimeMillis());
AppConfig.getInstance().setRootPackageName(clazz.getPackage().getName());
throw java.lang.NullPointerException.
Expected behavior
I think there should be a default value here instead of throwing an exception.
Describe the bug
在加载Interceptor时候的优化;
To Reproduce
ClassScanner类中的getCicadaInterceptor方法,原实现如下:
for (Class<?> cls : clsList) {
if (cls.getAnnotation(Interceptor.class) == null) {
continue;
}
Annotation[] annotations = cls.getAnnotations();
for (Annotation annotation : annotations) {
if (!(annotation instanceof Interceptor)) {
continue;
}
Interceptor interceptor = (Interceptor) annotation;
interceptorMap.put(interceptor.order(), cls);
}
}
建议改为:
for (Class<?> cls : clsList) {
Annotation annotation = cls.getAnnotation(Interceptor.class);
if (annotation == null) {
continue;
}
Interceptor interceptor = (Interceptor) annotation;
interceptorMap.put(interceptor.order(), cls);
}
Expected behavior
只需要执行一次cls.getAnnotation,没有必要取第二次遍历判断。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.