]> git.feebdaed.xyz Git - linuxyz.git/commitdiff
c and rust perfed
authorseantywork <seantywork@gmail.com>
Wed, 30 Apr 2025 00:49:36 +0000 (09:49 +0900)
committerseantywork <seantywork@gmail.com>
Wed, 30 Apr 2025 00:49:36 +0000 (09:49 +0900)
12 files changed:
0xetc/0xrs/ncat/src/main.rs
0xetc/0xrs/ncat/src/ncat/ncat.rs
0xetc/0xrs/ncat/test.sh
ncat/2505-01.xyz.md [new file with mode: 0644]
ncat/Makefile
ncat/main.c
ncat/ncat.c
ncat/ncat.h
ncat/test.sh
queue-concurrent-list/main.c [deleted file]
queue-list/Makefile [new file with mode: 0644]
queue-list/main.c [new file with mode: 0644]

index 477e124e3d04ea590e962264560cde8e1550e43d..9115d7195cd03fc07373ead1e58be5c872f18074 100644 (file)
@@ -25,7 +25,7 @@ fn main() -> process::ExitCode {
         return process::ExitCode::from(1u8);
     }
 
-
+    
     match ctrlc::set_handler(move || {
         NCAT::keyboard_interrupt();
     }) {
index c8a05f0443fa35e64c83bb45e4161fee68e7be8c..e3be96ae6344183d3bbf91e2286468e7bfa3663c 100644 (file)
@@ -133,7 +133,7 @@ pub fn runner(mut ncat_opts: Arc<Mutex<NcatOptions>>) -> Result<(), String> {
 
         thread::spawn(move || get_thread(nopts.clone(), Arc::new(Mutex::new(rxStream)), Arc::new(txString)));
 
-        let timeout = Duration::new(0, 500000000);
+        let timeout = Duration::new(0, 50000000);
 
         let done = rxString.recv_timeout(timeout).unwrap();
 
@@ -144,6 +144,7 @@ pub fn runner(mut ncat_opts: Arc<Mutex<NcatOptions>>) -> Result<(), String> {
             //println!("done: {}", tmp);
         }
 
+
         let result = listen_and_serve(ncat_opts.clone());
 
         return result;
@@ -213,6 +214,7 @@ fn client(mut ncat_opts: Arc<Mutex<NcatOptions>>, tx: Arc<SyncSender<TcpStream>>
 
             println!("failed to write: {}", wsize);
         }
+
     }
 
     return Ok(());
index 7cb4f39f0fafa43da030df2e3aa6e0f23b2c2025..39a5726f8d3b81e470b3a3c0a8494cc59ab13017 100755 (executable)
@@ -37,7 +37,7 @@ sleep 1
 
 echo "running test..."
 
-time ./ncat.out 192.168.62.6 9999 < test.txt
+sudo perf stat -d ./ncat.out 192.168.62.6 9999 < test.txt
 
 echo "test completed"
 
diff --git a/ncat/2505-01.xyz.md b/ncat/2505-01.xyz.md
new file mode 100644 (file)
index 0000000..9366adc
--- /dev/null
@@ -0,0 +1,283 @@
+#
+
+```shell
+
+
+thy@thy-Z370-HD3:~/hack/linux/linuxyz/ncat$ ./test.sh 
+creating interface...
+creating 1000000 entries...
+test.txt exists
+running test...
+
+ Performance counter stats for './ncat.out 192.168.62.6 9999':
+
+          1,149.31 msec task-clock                       #    0.692 CPUs utilized             
+                82      context-switches                 #   71.347 /sec                      
+                 5      cpu-migrations                   #    4.350 /sec                      
+                35      page-faults                      #   30.453 /sec                      
+     4,915,902,430      cycles                           #    4.277 GHz                         (49.85%)
+     3,736,492,322      instructions                     #    0.76  insn per cycle              (62.39%)
+       696,645,936      branches                         #  606.144 M/sec                       (62.46%)
+         4,626,299      branch-misses                    #    0.66% of all branches             (62.52%)
+       945,180,544      L1-dcache-loads                  #  822.391 M/sec                       (62.65%)
+        21,471,338      L1-dcache-load-misses            #    2.27% of all L1-dcache accesses   (62.65%)
+         1,514,938      LLC-loads                        #    1.318 M/sec                       (50.03%)
+           574,598      LLC-load-misses                  #   37.93% of all LL-cache accesses    (49.88%)
+
+       1.660428866 seconds time elapsed
+
+       0.573369000 seconds user
+       0.576371000 seconds sys
+
+
+test completed
+
+```
+
+#
+
+```shell
+
+thy@thy-Z370-HD3:~/hack/linux/linuxyz/0xetc/0xrs/ncat$ ./test.sh 
+creating interface...
+creating 1000000 entries...
+test.txt exists
+running test...
+
+ Performance counter stats for './ncat.out 192.168.62.6 9999':
+
+            989.07 msec task-clock                       #    0.445 CPUs utilized             
+               177      context-switches                 #  178.955 /sec                      
+                 4      cpu-migrations                   #    4.044 /sec                      
+                91      page-faults                      #   92.005 /sec                      
+     4,223,327,220      cycles                           #    4.270 GHz                         (49.90%)
+     3,930,952,505      instructions                     #    0.93  insn per cycle              (62.49%)
+       741,770,843      branches                         #  749.965 M/sec                       (62.53%)
+         4,071,413      branch-misses                    #    0.55% of all branches             (62.51%)
+       983,136,962      L1-dcache-loads                  #  993.997 M/sec                       (62.65%)
+        11,295,559      L1-dcache-load-misses            #    1.15% of all L1-dcache accesses   (62.63%)
+         1,445,219      LLC-loads                        #    1.461 M/sec                       (49.96%)
+           570,018      LLC-load-misses                  #   39.44% of all LL-cache accesses    (49.96%)
+
+       2.223086985 seconds time elapsed
+
+       0.516193000 seconds user
+       0.473260000 seconds sys
+
+
+test completed
+
+```
+
+
+#
+
+```c
+/*
+
+        TO SEE IF BOTTLENECK IS NETWORK IO
+
+        comms.datalen = htonl(content_len - header_size);
+        memcpy(comms.data, &comms.datalen, header_size);
+
+        int wb = write(sockfd, comms.data, content_len);
+
+        if(wb <= 0){
+
+            keepalive = 0;
+            continue;
+        }
+*/
+
+```
+
+```shell
+
+creating interface...
+creating 1000000 entries...
+test.txt exists
+running test...
+
+ Performance counter stats for './ncat.out 192.168.62.6 9999':
+
+            273.84 msec task-clock                       #    0.999 CPUs utilized             
+                 8      context-switches                 #   29.214 /sec                      
+                 0      cpu-migrations                   #    0.000 /sec                      
+                35      page-faults                      #  127.812 /sec                      
+     1,150,016,992      cycles                           #    4.200 GHz                         (49.80%)
+     1,140,874,002      instructions                     #    0.99  insn per cycle              (62.58%)
+       246,471,415      branches                         #  900.055 M/sec                       (62.76%)
+           187,193      branch-misses                    #    0.08% of all branches             (62.76%)
+       256,823,002      L1-dcache-loads                  #  937.856 M/sec                       (62.76%)
+         1,466,330      L1-dcache-load-misses            #    0.57% of all L1-dcache accesses   (62.64%)
+         1,088,490      LLC-loads                        #    3.975 M/sec                       (49.68%)
+           560,838      LLC-load-misses                  #   51.52% of all LL-cache accesses    (49.68%)
+
+       0.274222460 seconds time elapsed
+
+       0.260067000 seconds user
+       0.014003000 seconds sys
+
+
+test completed
+
+
+```
+
+# 
+
+```rust
+
+/*
+        TO SEE IF BOTTLENECK IS NETWORK IO
+        
+        let mut header = [0u8; 4];
+
+        let mut message_size = [0u32];
+
+        message_size[0] = message.len() as u32;
+
+        BigEndian::write_u32_into(&message_size, &mut header);
+
+        let mut wbuff_vec = header.to_vec();
+
+        let mut message_vec = message.as_bytes().to_vec();
+
+        wbuff_vec.append(&mut message_vec);
+
+        let wsize = io_stream.write(&wbuff_vec).unwrap();
+
+        if wsize <= 0 {
+
+            println!("failed to write: {}", wsize);
+        }
+*/
+
+```
+
+
+```shell
+
+creating interface...
+creating 1000000 entries...
+test.txt exists
+running test...
+
+ Performance counter stats for './ncat.out 192.168.62.6 9999':
+
+             77.45 msec task-clock                       #    0.997 CPUs utilized             
+                 4      context-switches                 #   51.649 /sec                      
+                 0      cpu-migrations                   #    0.000 /sec                      
+                89      page-faults                      #    1.149 K/sec                     
+       323,097,097      cycles                           #    4.172 GHz                         (48.18%)
+       764,047,641      instructions                     #    2.36  insn per cycle              (61.26%)
+       163,182,395      branches                         #    2.107 G/sec                       (61.55%)
+           309,205      branch-misses                    #    0.19% of all branches             (62.84%)
+       168,826,594      L1-dcache-loads                  #    2.180 G/sec                       (64.14%)
+         1,486,727      L1-dcache-load-misses            #    0.88% of all L1-dcache accesses   (64.63%)
+           996,921      LLC-loads                        #   12.872 M/sec                       (50.18%)
+           499,547      LLC-load-misses                  #   50.11% of all LL-cache accesses    (48.96%)
+
+       0.077660220 seconds time elapsed
+
+       0.067662000 seconds user
+       0.009950000 seconds sys
+
+
+test completed
+
+
+
+```
+
+
+
+# 
+
+```c
+
+    uint8_t data_static[4 + INPUT_BUFF_CHUNK] = {0};
+
+    while(keepalive){
+
+        content_len = header_size + 0;
+
+//       comms.data = (uint8_t*)malloc(header_size + (INPUT_BUFF_CHUNK));
+
+        comms.data = data_static;
+
+        memset(comms.data, 0, header_size + (INPUT_BUFF_CHUNK));
+
+        pthread_mutex_lock(&stdlock);
+
+        fgets(comms.data + header_size, INPUT_BUFF_CHUNK - header_size, stdin);
+
+        pthread_mutex_unlock(&stdlock);
+
+        message_len = strlen(comms.data + header_size);
+
+        content_len += message_len - 1;
+
+        comms.data[content_len] = 0;
+
+//        comms.data = (uint8_t*)realloc(comms.data, content_len);
+
+        if(strcmp(CLIENT_EXIT, (char*)(comms.data + header_size)) == 0){
+
+            keepalive = 0;
+            comms.data = NULL;
+            continue;
+        }
+
+/*
+        comms.datalen = htonl(content_len - header_size);
+        memcpy(comms.data, &comms.datalen, header_size);
+
+        int wb = write(sockfd, comms.data, content_len);
+
+        if(wb <= 0){
+
+            keepalive = 0;
+            continue;
+        }
+*/
+//        free(comms.data);
+
+
+    }   
+
+```
+
+
+```shell
+thy@thy-Z370-HD3:~/hack/linux/linuxyz/ncat$ ./test.sh 
+creating interface...
+creating 1000000 entries...
+test.txt exists
+running test...
+
+ Performance counter stats for './ncat.out 192.168.62.6 9999':
+
+            143.93 msec task-clock                       #    0.997 CPUs utilized             
+                 2      context-switches                 #   13.896 /sec                      
+                 0      cpu-migrations                   #    0.000 /sec                      
+                32      page-faults                      #  222.330 /sec                      
+       541,504,050      cycles                           #    3.762 GHz                         (49.92%)
+       392,731,304      instructions                     #    0.73  insn per cycle              (62.48%)
+        85,665,835      branches                         #  595.189 M/sec                       (62.49%)
+           156,129      branch-misses                    #    0.18% of all branches             (62.48%)
+        91,212,527      L1-dcache-loads                  #  633.727 M/sec                       (62.48%)
+         1,385,077      L1-dcache-load-misses            #    1.52% of all L1-dcache accesses   (62.63%)
+           982,215      LLC-loads                        #    6.824 M/sec                       (50.06%)
+           476,824      LLC-load-misses                  #   48.55% of all LL-cache accesses    (50.08%)
+
+       0.144311729 seconds time elapsed
+
+       0.128300000 seconds user
+       0.016037000 seconds sys
+
+
+test completed
+
+
+```
\ No newline at end of file
index cefe4e783190f0585b7d166f4b0f01043708ac79..bc49cf2936f4a670c40e024418acb4b6c68c9599 100644 (file)
@@ -1,4 +1,4 @@
-GCC_FLAGS := -Wall -O2
+GCC_FLAGS := -Wall -O2 -static
 
 
 all: ncat.o
index 016786654e62c7d3ef0e8ab9bdf1111b87158969..f1d569797d27052642f3cc0f8c70392c7ad67b5f 100644 (file)
@@ -1,6 +1,6 @@
 #include "ncat.h"
 
-pthread_mutex_t no_locker;
+
 NCAT_OPTIONS ncat_opts;
 char* serve_content = NULL;
 int _exit_prog = 0;
@@ -21,7 +21,6 @@ int main(int argc, char** argv){
 
     }
 
-    pthread_mutex_init(&no_locker, NULL);
 
     int parsed = NCAT_parse_args(argc - 1, &argv[1]);
 
index 674ad007fe7ae650de936c588a0651a23b60219d..efbfe7ef4640ffafff58a09c5b6cf339a8b1d12d 100644 (file)
@@ -198,11 +198,14 @@ int NCAT_client(){
     int content_len = 0;
     int message_len = 0;
 
+    pthread_mutex_t stdlock;
+
+    pthread_mutex_init(&stdlock, NULL);
+
     int header_size = sizeof(uint32_t);
 
     memset(&comms, 0, sizeof(comms));
 
-    pthread_mutex_lock(&no_locker);
 
     sockfd = socket(AF_INET, SOCK_STREAM, 0);
     if (sockfd == -1) {
@@ -224,8 +227,7 @@ int NCAT_client(){
     ncat_opts._client_sockfd = sockfd;
     ncat_opts._client_sock_ready = 1;
 
-
-    pthread_mutex_unlock(&no_locker);
+    //uint8_t data_static[4 + INPUT_BUFF_CHUNK] = {0};
 
     while(keepalive){
 
@@ -233,10 +235,16 @@ int NCAT_client(){
 
         comms.data = (uint8_t*)malloc(header_size + (INPUT_BUFF_CHUNK));
 
+//      comms.data = data_static;
+
         memset(comms.data, 0, header_size + (INPUT_BUFF_CHUNK));
 
+        pthread_mutex_lock(&stdlock);
+
         fgets(comms.data + header_size, INPUT_BUFF_CHUNK - header_size, stdin);
 
+        pthread_mutex_unlock(&stdlock);
+
         message_len = strlen(comms.data + header_size);
 
         content_len += message_len - 1;
@@ -248,9 +256,11 @@ int NCAT_client(){
         if(strcmp(CLIENT_EXIT, (char*)(comms.data + header_size)) == 0){
 
             keepalive = 0;
+//            comms.data = NULL;
             continue;
         }
 
+
         comms.datalen = htonl(content_len - header_size);
         memcpy(comms.data, &comms.datalen, header_size);
 
@@ -304,9 +314,6 @@ int NCAT_listen_and_serve(){
 
     memset(&comms, 0, sizeof(comms));
 
-    pthread_mutex_lock(&no_locker);
-
-    pthread_mutex_unlock(&no_locker);
 
 
     sockfd = socket(AF_INET, SOCK_STREAM, 0); 
@@ -462,12 +469,8 @@ srv_out:
 
 void* NCAT_get_thread(){
 
-    pthread_mutex_lock(&no_locker);
-
     if(ncat_opts.mode_client){
 
-        pthread_mutex_unlock(&no_locker);
-
         NCAT_COMMS comms;
 
         memset(&comms, 0, sizeof(NCAT_COMMS));
@@ -599,7 +602,6 @@ void* NCAT_get_thread(){
             write(ncat_opts._server_sig[1], SERVER_SIG_DONE, SERVER_SIG_LEN);
         }
 
-        pthread_mutex_unlock(&no_locker);
 
     }
 
index 5d9599ef11152f108f053f9793755da007538582..3631207417ee3d316e4963eb61548eb35070d116 100644 (file)
 #include <fcntl.h>
 #include <poll.h>
 
-#define INPUT_BUFF_CHUNK 1024
+#define INPUT_BUFF_CHUNK 1024 * 8
 #define SERVER_SIG_DONE "done"
 #define SERVER_SIG_LEN     4
 #define SERVER_SIG_TIMEOUT_COUNT 5
-#define SERVER_SIG_TIMEOUT_MS 100
+#define SERVER_SIG_TIMEOUT_MS 10
 #define CLIENT_EXIT     "exit"
 
 typedef struct NCAT_OPTIONS {
@@ -42,7 +42,7 @@ typedef struct __attribute__((packed)) NCAT_COMMS {
     uint8_t* data;
 } NCAT_COMMS;
 
-extern pthread_mutex_t no_locker;
+
 extern NCAT_OPTIONS ncat_opts;
 extern char* serve_content;
 extern int _exit_prog;
index ee10ad4cf55ba502c951d9ef6e5126cc6cae31d1..e41270e96b1a789b2ac93951298a3a3c7aaec8b8 100755 (executable)
@@ -38,7 +38,7 @@ sleep 1
 
 echo "running test..."
 
-time ./ncat.out 192.168.62.6 9999 < test.txt
+sudo perf stat -d ./ncat.out 192.168.62.6 9999 < test.txt
 
 echo "test completed"
 
diff --git a/queue-concurrent-list/main.c b/queue-concurrent-list/main.c
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/queue-list/Makefile b/queue-list/Makefile
new file mode 100644 (file)
index 0000000..333be65
--- /dev/null
@@ -0,0 +1,6 @@
+all:
+
+       gcc -o test.out main.c 
+
+clean:
+       rm -rf *.out
\ No newline at end of file
diff --git a/queue-list/main.c b/queue-list/main.c
new file mode 100644 (file)
index 0000000..e69de29