Explorar o código

EVPP_HEADERS, check_option, benchmark

ithewei %!s(int64=4) %!d(string=hai) anos
pai
achega
e037e6b6d8
Modificáronse 12 ficheiros con 86 adicións e 8 borrados
  1. 1 1
      CMakeLists.txt
  2. 1 1
      Makefile
  3. 13 0
      Makefile.vars
  4. 12 1
      README.md
  5. 2 0
      base/hmap.h
  6. 15 0
      cmake/vars.cmake
  7. 20 0
      configure
  8. 1 1
      docs/PLAN.md
  9. 3 0
      hconfig.h
  10. 3 0
      hconfig.h.in
  11. 12 1
      readme_cn.md
  12. 3 3
      utils/base64.h

+ 1 - 1
CMakeLists.txt

@@ -136,7 +136,7 @@ endif()
 set(ALL_SRCDIRS . base utils event protocol http http/client http/server consul examples)
 set(LIBHV_SRCDIRS . base utils event evpp)
 set(LIBHV_HEADERS hv.h hconfig.h hexport.h)
-set(LIBHV_HEADERS ${LIBHV_HEADERS} ${BASE_HEADERS} ${UTILS_HEADERS} ${EVENT_HEADERS})
+set(LIBHV_HEADERS ${LIBHV_HEADERS} ${BASE_HEADERS} ${UTILS_HEADERS} ${EVENT_HEADERS} ${EVPP_HEADERS})
 
 if(WITH_PROTOCOL)
     set(LIBHV_HEADERS ${LIBHV_HEADERS} ${PROTOCOL_HEADERS})

+ 1 - 1
Makefile

@@ -6,7 +6,7 @@ ALL_SRCDIRS=. base utils event protocol http http/client http/server consul
 
 LIBHV_SRCDIRS = . base utils event evpp
 LIBHV_HEADERS = hv.h hconfig.h hexport.h
-LIBHV_HEADERS += $(BASE_HEADERS) $(UTILS_HEADERS) $(EVENT_HEADERS)
+LIBHV_HEADERS += $(BASE_HEADERS) $(UTILS_HEADERS) $(EVENT_HEADERS) $(EVPP_HEADERS)
 
 ifeq ($(WITH_PROTOCOL), yes)
 LIBHV_HEADERS += $(PROTOCOL_HEADERS)

+ 13 - 0
Makefile.vars

@@ -47,6 +47,19 @@ EVENT_HEADERS = event/hloop.h\
 				event/nlog.h\
 				event/nmap.h\
 
+EVPP_HEADERS  = evpp/Buffer.h\
+				evpp/Callback.h\
+				evpp/Channel.h\
+				evpp/Event.h\
+				evpp/EventLoop.h\
+				evpp/EventLoopThread.h\
+				evpp/EventLoopThreadPool.h\
+				evpp/Status.h\
+				evpp/TcpClient.h\
+				evpp/TcpServer.h\
+				evpp/UdpClient.h\
+				evpp/UdpServer.h\
+
 PROTOCOL_HEADERS =  protocol/icmp.h\
 					protocol/dns.h\
 					protocol/ftp.h\

+ 12 - 1
README.md

@@ -98,6 +98,7 @@ int main() {
 }
 ```
 
+#### httpd/curl
 ```shell
 git clone https://github.com/ithewei/libhv.git
 cd libhv
@@ -128,10 +129,20 @@ bin/curl -v localhost:8080/test -H "Content-Type:application/json" -d '{"bool":t
 bin/curl -v localhost:8080/test -F 'bool=1 int=123 float=3.14 string=hello'
 # RESTful API: /group/:group_name/user/:user_id
 bin/curl -v -X DELETE localhost:8080/group/test/user/123
+```
 
+#### benchmark
+```shell
 # webbench (linux only)
 make webbench
-bin/webbench -c 2 -t 60 localhost:8080
+bin/webbench -c 2 -t 10 http://127.0.0.1:8080/
+bin/webbench -k -c 2 -t 10 http://127.0.0.1:8080/
+
+# sudo apt install apache2-utils
+ab -c 100 -n 100000 http://127.0.0.1:8080/
+
+# sudo apt install wrk
+wrk -c 100 -t 4 -d 10s http://127.0.0.1:8080/
 ```
 
 **libhv(port:8080) vs nginx(port:80)**

+ 2 - 0
base/hmap.h

@@ -1,6 +1,8 @@
 #ifndef HV_MAP_H_
 #define HV_MAP_H_
 
+#include "hconfig.h"
+
 #include <map>
 #include <string>
 

+ 15 - 0
cmake/vars.cmake

@@ -46,6 +46,21 @@ set(EVENT_HEADERS
     event/nmap.h
 )
 
+set(EVPP_HEADERS
+    evpp/Buffer.h
+    evpp/Callback.h
+    evpp/Channel.h
+    evpp/Event.h
+    evpp/EventLoop.h
+    evpp/EventLoopThread.h
+    evpp/EventLoopThreadPool.h
+    evpp/Status.h
+    evpp/TcpClient.h
+    evpp/TcpServer.h
+    evpp/UdpClient.h
+    evpp/UdpServer.h
+)
+
 set(PROTOCOL_HEADERS
     protocol/icmp.h
     protocol/dns.h

+ 20 - 0
configure

@@ -85,6 +85,20 @@ macro=HAVE_$(echo $function | tr a-z A-Z)
 write_define
 }
 
+check_option() {
+value=$(eval echo \$$option)
+echo "checking for $option=$value"
+if [ "$value" == "yes" ]; then
+cat << END >> $confile
+#define $option 1
+END
+else
+cat << END >> $confile
+/* #undef $option */
+END
+fi
+}
+
 # Checks for os
 echo "checking for os..."
 HOST_OS=`uname -s`
@@ -129,8 +143,14 @@ function=pthread_spin_lock && header=pthread.h && check_function
 function=pthread_mutex_timedlock && header=pthread.h && check_function
 function=sem_timedwait && header=semaphore.h && check_function
 
+# Checks for options
+source config.mk
+option=ENABLE_UDS && check_option
+option=USE_MULTIMAP && check_option
+
 # end confile
 cat << END >> $confile
+
 #endif // HV_CONFIG_H_
 END
 

+ 1 - 1
docs/PLAN.md

@@ -1,6 +1,7 @@
 ## Done
 
 - event: select/poll/epoll/kqueue/port
+- evpp: c++ EventLoop interface similar to muduo and evpp
 - http client/server: include https http1/x http2
 
 ## Improving
@@ -9,7 +10,6 @@
 
 ## Plan
 
-- evpp: c++ EventLoop interface similar to muduo and evpp
 - websocket client/server
 - mqtt client
 - redis client

+ 3 - 0
hconfig.h

@@ -65,4 +65,7 @@
 #define HAVE_SEM_TIMEDWAIT 0
 #endif
 
+/* #undef ENABLE_UDS */
+/* #undef USE_MULTIMAP */
+
 #endif // HV_CONFIG_H_

+ 3 - 0
hconfig.h.in

@@ -65,4 +65,7 @@
 #define HAVE_SEM_TIMEDWAIT @HAVE_SEM_TIMEDWAIT@
 #endif
 
+#cmakedefine ENABLE_UDS     1
+#cmakedefine USE_MULTIMAP   1
+
 #endif // HV_CONFIG_H_

+ 12 - 1
readme_cn.md

@@ -96,6 +96,7 @@ int main() {
 }
 ```
 
+#### httpd/curl
 ```shell
 git clone https://github.com/ithewei/libhv.git
 cd libhv
@@ -126,10 +127,20 @@ bin/curl -v localhost:8080/test -H "Content-Type:application/json" -d '{"bool":t
 bin/curl -v localhost:8080/test -F 'bool=1 int=123 float=3.14 string=hello'
 # RESTful API: /group/:group_name/user/:user_id
 bin/curl -v -X DELETE localhost:8080/group/test/user/123
+```
 
+#### benchmark
+```shell
 # webbench (linux only)
 make webbench
-bin/webbench -c 2 -t 60 localhost:8080
+bin/webbench -c 2 -t 10 http://127.0.0.1:8080/
+bin/webbench -k -c 2 -t 10 http://127.0.0.1:8080/
+
+# sudo apt install apache2-utils
+ab -c 100 -n 100000 http://127.0.0.1:8080/
+
+# sudo apt install wrk
+wrk -c 100 -t 4 -d 10s http://127.0.0.1:8080/
 ```
 
 **libhv(port:8080) vs nginx(port:80)**

+ 3 - 3
utils/base64.h

@@ -1,5 +1,5 @@
-#ifndef __BASE64_H__
-#define __BASE64_H__
+#ifndef HV_BASE64_H_
+#define HV_BASE64_H_
 
 #include "hexport.h"
 
@@ -15,4 +15,4 @@ HV_EXPORT int base64_decode(const char *in, unsigned int inlen, unsigned char *o
 
 END_EXTERN_C
 
-#endif // __BASE64_H__
+#endif // HV_BASE64_H_