Dynamically adjusting thread pool sizes and http connection counts [on hold]

I am working on a transaction interface API where we are setting hardcoded thread pool sizes and connection counts, which we adjust by running manual stress tests and measuring how many transactions go through per second, and tweaking those by hand until we get acceptable numbers.

This got me thinking there should be a way for the application to do it itself based on certain parameters but not sure how to go about it. What are some approaches to automate this process?

This is a Spring based web API if that is relevant.

How to apply Memory Allocation? (eg. malloc, calloc, free) This C Program counts the amount of words in a list?

Considering the code provided by @David C. Rankin in this previous answer:


How do you optimise this code to include Memory Allocation for much larger text files? With this code below it will complete for small .txt files.

However, what is the best way to set memory allocation to this code so that C (Programming Language) does not run out of memory. Is it best to use linked lists?

/**  * C program to count occurrences of all words in a file.  */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <limits.h>  #define MAX_WORD     50     /* max word size */ #define MAX_WORDS   512     /* max number of words */  #ifndef PATH_MAX #define PATH_MAX   2048     /* max path (defined for Linux in limits.h) */ #endif  typedef struct {            /* use a struct to hold */     char word[MAX_WORD];    /* lowercase word, and */     int cap, count;         /* if it appeast capitalized, and its count */ } words_t;  char *strlwr (char *str)    /* no need for unsigned char */ {     char *p = str;      while (*p) {         *p = tolower(*p);         p++;     }      return str; }  int main (void) {      FILE *fptr;     char path[PATH_MAX], word[MAX_WORD];     size_t i, len, index = 0;      /* Array of struct of distinct words, initialized all zero */     words_t words[MAX_WORDS] = {{ .word = "" }};      /* Input file path */     printf ("Enter file path: ");     if (scanf ("%s", path) != 1) {  /* validate every input */         fputs ("error: invalid file path or cancellation.\n", stderr);         return 1;     }      fptr = fopen (path, "r");   /* open file */     if (fptr == NULL) {         /* validate file open */         fputs ( "Unable to open file.\n"                 "Please check you have read privileges.\n", stderr);         exit (EXIT_FAILURE);     }      while (index < MAX_WORDS &&                 /* protect array bounds  */             fscanf (fptr, "%s", word) == 1) {   /* while valid word read */         int iscap = 0, isunique = 1;    /* is captial, is unique flags */          if (isupper (*word))            /* is the word uppercase */             iscap = 1;          /* remove all trailing punctuation characters */         len = strlen (word);                    /* get length */         while (len && ispunct(word[len - 1]))   /* only if len > 0 */             word[--len] = 0;          strlwr (word);                  /* convert word to lowercase */          /* check if word exits in list of all distinct words */         for (i = 0; i < index; i++) {             if (strcmp(words[i].word, word) == 0) {                 isunique = 0;               /* set unique flag zero */                 if (iscap)                  /* if capital flag set */                     words[i].cap = iscap;   /* set capital flag in struct */                 words[i].count++;           /* increment word count */                 break;                      /* bail - done */             }         }         if (isunique) { /* if unique, add to array, increment index */             memcpy (words[index].word, word, len + 1);  /* have len */             if (iscap)                      /* if cap flag set */                 words[index].cap = iscap;   /* set capital flag in struct */             words[index++].count++;         /* increment count & index */         }     }     fclose (fptr);  /* close file */      /*      * Print occurrences of all words in file.      */     puts ("\nOccurrences of all distinct words with Cap in file:");     for (i = 0; i < index; i++) {         if (words[i].cap) {             strcpy (word, words[i].word);             *word = toupper (*word);             /*              * %-15s prints string in 15 character width.              * - is used to print string left align inside              * 15 character width space.              */             printf("%-15s %d\n", word, words[i].count);         }     }      return 0; } 

Example Use/Output

Using your posted input

$   ./bin/unique_words_with_cap Enter file path: dat/girljumped.txt  Occurrences of all distinct words with Cap in file: Any             7 One             4 Some            10 The             6 A               13 

Is it possible to set dates across a row of cells where each cell date counts back different amounts of weekdays from a completion date?

I manage digital marketing campaigns from end-to-end, and there are various steps within each campaign’s production process that are due certain dates out from and relative to a final launch date, which may be subject to change.

In Google Sheets, I would like to be able to input a launch date and have each step leading up to it display its due date a specific amount of weekdays out from the launch date. If the launch date changes, I would like all the dates in the steps that come before it to change dynamically/automatically with it.

e.g. The launch date is 23-12-2019, but the last step in the process is due one weekday before the launch date, so it must display 20-12-2019; the second last step is due 3 weekdays before the launch date, so it must display 18-12-2019, and so on…

This was once possible in a former role where I used Excel, but I am at a loss for how to set this in Google Sheets. I would then like to set conditional formatting so that if the due date per step arrives, that it turns red, but remains colourless otherwise.

I would appreciate any assistance you can give me.

Is there a web-based Gmail client that counts All messages in inbox not just Unread ones?

I was a happy user of Wavebox until today; it’s fast, reliable and full of features making the experience more macOS native-like. One thing that works very well for me is the option to “Count all message in inbox” not just the unread one.

The newest beta version removed the option to count all inbox messages, so my workflow is broken.

What web based Gmail clients for macOS can count all inbox messages, not just unread?

I know there are many native email clients that have this option, but I need the web interface.

A simple decorator written as a class, which counts how many times a function has been called

Can I improve its typing? Is there any other improvement or pythonic change that you would do?

F = TypeVar('F', bound=Callable[..., Any])   # This is mostly so that I practice using a class as a decorator. class CountCalls:     """Logs to DEBUG how many times a function gets called, saves the result in a newly created attribute `num_calls`."""     def __init__(self, func: F) -> None:         functools.update_wrapper(self, func)         self.func = func         self.num_calls: int = 0         self._logger = logging.getLogger(__name__ + '.' + self.func.__name__)         self.last_return_value = None      def __call__(self, *args: Any, **kwargs: Any) -> Any:         self.num_calls += 1         self._logger.debug(' called %s times', self.num_calls)         self.last_return_value = self.func(*args, **kwargs)         return self.last_return_value 

Here’s the decorator in action:

@CountCalls def asdf(var: str):     print(var)     return len(var) asdf(5) Traceback (most recent call last):   File "<input>", line 1, in <module>   File "C:/Projects/Python/he/src/he/decorators.py", line 139, in __call__     self.last_return_value = self.func(*args, **kwargs)   File "<input>", line 4, in asdf TypeError: object of type 'int' has no len() 5 asdf('Laur') Laur 4 asdf.last_return_value 4 asdf('fake gangsta') fake gangsta 12 

Can’t get counts back from large table in Postgres

I have a table with 1.2 billion rows in it. The table has 60-70 columns, the vast majority of which are empty.

The table is indexed on subscription_id, among other indexes.

My query is:

SELECT count(distinct listing_id) FROM "apps" WHERE "apps"."subscription_id" = 1298 

This particular subscription_id is going to have roughly 30M rows to count. Unfortunately I am unable to do so as the query takes in excess of one hour just to get that count.

I know there must be some way to improve it. Would it be improved if I created an index on subscription_id and listing_id together?

Representation of Subgraph Counts using Polynomial of Adjacency Matrix

We consider a graph $ G$ of size $ d$ with adjacency matrix $ A$ , whose entries take value in $ \{0,1\}$ . We are interested in the number of a certain connected subgraph $ S$ of size $ k$ in $ G$ . For example, the subgraph $ S$ consists of edges $ (1,2),(2,3),(3,4),(4,2)$ up to relabeling of the $ k = 4$ vertices $ 1,2,3,4$ . We can also view this subgraph as a path of length $ k = 4$ from vertex $ 1$ to vertex $ 2$ . Here we allow repeated vertices in the path, for example, vertex $ 2$ appears twice.

Question: Is the following claim true?

Let $ s$ denote the number of subgraphs $ S$ in $ G$ . For any graph $ G$ and subgraph $ S$ , there exist $ \{\Theta^{(i)}\}_{i=1}^k$ that $ $ s = \sum_{i = 1}^k\langle \Theta^{(i)}, A^i \rangle, $ $ where $ \Theta^{(i)} \in \mathbb{R}^{d\times d}$ is the coefficient of the $ i$ -th order polynomial of the adjacency matrix $ A$ , and $ k$ is the size of the subgraph of interest.

Script that counts quarters, dimes, nickels, and pennies

I am learning python and I wrote a script that counts how many coins you would need for an amount in dollars. I was wondering if I could make any improvements to it.

def change():     amnt = float(input("Enter an amount in USD: "))     quarters = divmod(amnt, 0.25)     print("Quarters: ", quarters[0])     amnt = round(quarters[1], 2)     dimes = divmod(amnt, 0.10)     print("Dimes: ", dimes[0])     amnt = round(dimes[1], 2)     nickels = divmod(amnt, 0.     print("Nickels: ", nickels[0])     amnt = round(nickels[1], 2)     penny = divmod(amnt, 0.01)     print("Pennies", penny[0]) change()